[Freeipa-devel] [PATCH] Allow set/add/del to be called multiple times
Karl MacMillan
kmacmill at redhat.com
Wed Oct 31 20:00:00 UTC 2007
# HG changeset patch
# User "Karl MacMillan <kmacmill at redhat.com>"
# Date 1193860768 14400
# Node ID 5a615adb8952a20ffa0ca0fc02b578f464622153
# Parent 1ac86e5c2e662d5ae2e91f56780f7ca1f78f063d
Allow set/add/del to be called multiple times.
Allow the --set/add/del options to be called multiple
times during the same invocation. Also add more robust
checking of errors.
diff -r 1ac86e5c2e66 -r 5a615adb8952 ipa-admintools/ipa-usermod
--- a/ipa-admintools/ipa-usermod Wed Oct 31 10:08:16 2007 -0400
+++ b/ipa-admintools/ipa-usermod Wed Oct 31 15:59:28 2007 -0400
@@ -33,6 +33,9 @@ def usage():
def usage():
print "ipa-usermod [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell STRING] [--add attribute=value(,value1,..,valuen)] [--del attribute] [--set attribute=value(,value1,..,valuen)] user"
sys.exit(1)
+
+def set_add_usage(which):
+ print "%s option usage: --%s NAME=VALUE" % (which, which)
def parse_options():
parser = OptionParser()
@@ -47,11 +50,13 @@ def parse_options():
parser.add_option("-s", "--shell", dest="shell",
help="Set user's login shell to shell")
parser.add_option("--add", dest="addattr",
- help="Adds an attribute or values to that attribute, attr=value(,value1,value2)")
+ help="Adds an attribute or values to that attribute, attr=value(,value1,value2)",
+ action="append")
parser.add_option("--del", dest="delattr",
- help="Remove an attribute")
+ help="Remove an attribute", action="append")
parser.add_option("--set", dest="setattr",
- help="Set an attribute, dropping any existing values that may exist")
+ help="Set an attribute, dropping any existing values that may exist",
+ action="append")
parser.add_option("-M", "--mailAddress", dest="mail",
help="Set user's e-mail address")
parser.add_option("--usage", action="store_true",
@@ -194,24 +199,36 @@ def main():
if shell:
user.setValue('loginshell', shell)
+ if options.delattr:
+ for d in options.delattr:
+ # doesn't truly delete the attribute but does null out the value
+ user.setValue(d, '')
+
if options.setattr:
- (attr,value) = options.setattr.split('=')
- values = value.split(',')
- user.setValue(attr, values)
+ for s in options.setattr:
+ s = s.split('=')
+ if len(s) != 2:
+ set_add_usage("set")
+ sys.exit(1)
+ (attr,value) = s
+ values = value.split(',')
+ user.setValue(attr, values)
if options.addattr:
- (attr,value) = options.addattr.split('=')
- values = value.split(',')
- cvalue = user.getValue(attr)
- if cvalue:
- if isinstance(cvalue,str):
- cvalue = [cvalue]
- values = cvalue + values
- user.setValue(attr, values)
-
- if options.delattr:
- # doesn't truly delete the attribute but does null out the value
- user.setValue(options.delattr, '')
+ for a in options.addattr:
+ a = a.split('=')
+ if len(a) != 2:
+ set_add_usage("add")
+ sys.exit(1)
+ (attr,value) = a
+ values = value.split(',')
+ cvalue = user.getValue(attr)
+ if cvalue:
+ if isinstance(cvalue,str):
+ cvalue = [cvalue]
+ values = cvalue + values
+ user.setValue(attr, values)
+
try:
client.update_user(user)
More information about the Freeipa-devel
mailing list