@@ -, +, @@ --- .../modules/univention/admincli/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -476,7 +476,7 @@ def _doit(arglist): elif opt == '--logfile': logfile=val elif opt == '--policies': - policies = True + list_policies = True if val=="1": policies_with_DN = True else: -- --- .../modules/univention/admincli/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -934,7 +934,7 @@ def _doit(arglist): out.append("need new position for moving object") else: res = '' - try: # check if goal-position exists + try: # check if global-position exists res = lo.get(position_dn) except: pass -- --- .../modules/univention/admincli/admin.py | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -95,7 +95,6 @@ def usage(): out.append(' --%-30s %s' % ('bindpwd', 'bind password')) out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) out.append(' --%-30s %s' % ('dn', 'Edit object with DN')) - out.append(' --%-30s %s' % ('arg', 'Edit object with ARG')) out.append(' --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar')) out.append(' --%-30s %s' % ('append', 'Append value to variable, e.g. foo=bar')) out.append(' --%-30s %s' % ('remove', 'Remove value from variable, e.g. foo=bar')) @@ -113,7 +112,6 @@ def usage(): out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) out.append(' --%-30s %s' % ('dn', 'Remove object with DN')) out.append(' --%-30s %s' % ('superordinate', 'Use superordinate module')) - out.append(' --%-30s %s' % ('arg', 'Remove object with ARG')) out.append(' --%-30s %s' % ('filter', 'Lookup filter e.g. foo=bar')) out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) out.append(' --%-30s %s' % ('remove_referring', 'remove referring objects')) @@ -435,7 +433,30 @@ def _doit(arglist): remove_referring=0 recursive=1 # parse options - longopts=['position=', 'dn=', 'arg=', 'set=', 'append=', 'remove=', 'superordinate=', 'option=', 'append-option=', 'filter=', 'tls=', 'ignore_exists', 'logfile=', 'policies=', 'binddn=', 'bindpwd=', 'bindpwdfile=', 'customattribute=', 'customattribute-remove=','policy-reference=','policy-dereference=','remove_referring','recursive'] + longopts = [ + 'position=', + 'dn=', + 'set=', + 'append=', + 'remove=', + 'superordinate=', + 'option=', + 'append-option=', + 'filter=', + 'tls=', + 'ignore_exists', + 'logfile=', + 'policies=', + 'binddn=', + 'bindpwd=', + 'bindpwdfile=', + 'customattribute=', + 'customattribute-remove=', + 'policy-reference=', + 'policy-dereference=', + 'remove_referring', + 'recursive' + ] try: opts, args=getopt.getopt(arglist[3:], '', longopts) except getopt.error, msg: @@ -450,7 +471,6 @@ def _doit(arglist): position_dn='' dn='' - arg=None binddn=None bindpwd=None list_policies=False @@ -494,8 +514,6 @@ def _doit(arglist): return out + ['OPERATION FAILED'] elif opt == '--dn': dn = _2utf8( val ) - elif opt == '--arg': - arg=val elif opt == '--tls': tls=val elif opt == '--ignore_exists': @@ -1121,7 +1139,6 @@ def _doit(arglist): try: for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter): out.append( 'DN: %s' % _2utf8( univention.admin.objects.dn (object ) ) ) - out.append( 'ARG: %s' % univention.admin.objects.arg( object ) ) if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'): object.open() -- --- .../modules/univention/admincli/admin.py | 132 --------------------- 1 file changed, 132 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -85,7 +85,6 @@ def usage(): out.append(' --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar')) out.append(' --%-30s %s' % ('superordinate', 'Use superordinate module')) out.append(' --%-30s %s' % ('option', 'Use only given module options')) - out.append(' --%-30s %s' % ('customattribute', 'Set custom attribute foo=bar')) out.append(' --%-30s %s' % ('policy-reference', 'Reference to policy given by DN')) out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) out.append(' --%-30s ' % ('ignore_exists')) @@ -100,8 +99,6 @@ def usage(): out.append(' --%-30s %s' % ('remove', 'Remove value from variable, e.g. foo=bar')) out.append(' --%-30s %s' % ('option', 'Use only given module options')) out.append(' --%-30s %s' % ('append-option', 'Append the module options')) - out.append(' --%-30s %s' % ('customattribute', 'Set custom attribute foo=bar')) - out.append(' --%-30s %s' % ('customattribute-remove', 'Remove custom attribute')) out.append(' --%-30s %s' % ('policy-reference', 'Reference to policy given by DN')) out.append(' --%-30s %s' % ('policy-dereference', 'Remove reference to policy given by DN')) out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) @@ -450,8 +447,6 @@ def _doit(arglist): 'binddn=', 'bindpwd=', 'bindpwdfile=', - 'customattribute=', - 'customattribute-remove=', 'policy-reference=', 'policy-dereference=', 'remove_referring', @@ -486,8 +481,6 @@ def _doit(arglist): input={} append={} remove={} - customattribute={} - customattribute_remove=[] policy_reference=[] policy_dereference=[] for opt, val in opts: @@ -526,21 +519,6 @@ def _doit(arglist): parsed_append_options.append(val) elif opt == '--filter': filter=val - elif opt == '--customattribute': - pos=val.find('=') - name=val[:pos] - value= _2utf8( val[ pos + 1 : ] ) - if not customattribute.has_key(name): - customattribute[name]=[] - customattribute[name].append(value) - elif opt == '--customattribute-remove': - pos=val.find('=') - if pos == -1: - customattribute_remove.append((val,None)) - else: - name=val[:pos] - value = _2utf8( val[ pos + 1 : ] ) - customattribute_remove.append((name,value)) elif opt == '--policy-reference': policy_reference.append(val) elif opt == '--policy-dereference': @@ -725,53 +703,7 @@ def _doit(arglist): recursive=1 - extraOC=[] - extraAttributes=[] - customattributes_set =[] - if hasattr(module, 'ldap_extra_objectclasses') and action in ['modify','edit','create','new']: - for oc, pname, syntax, ldapMapping, deleteValues, deleteObjectClass in module.ldap_extra_objectclasses: - if customattribute.has_key(module.property_descriptions[pname].short_description): - customattributes_set.append(module.property_descriptions[pname].short_description) - extraOC.append(oc); - # check multivalue - if module.property_descriptions[pname].multivalue: - if action in ['create','new'] or not dn or dn == '': - values_found=[] - else: - values_found=lo.search(base=dn, attr=[ldapMapping]) - for i in customattribute[module.property_descriptions[pname].short_description]: - value_already_set=0 - for tmp,val in values_found: - if val.has_key(ldapMapping): - if i in val[ldapMapping]: - value_already_set=1 - if value_already_set: - out.append('WARNING: customattribute %s is already set to %s'%(module.property_descriptions[pname].short_description,i)) - else: - extraAttributes.append((ldapMapping,'',[i])) - else: - if len(customattribute[module.property_descriptions[pname].short_description])>1: - out.append('WARNING: cannot set singlevalue customattribute "%s" with more than one entry'%module.property_descriptions[pname].short_description) - else: - replaced=0 - if action in ['create','new'] or not dn or dn == '': - values_found=[] - else: - values_found=lo.search(base=dn, attr=[ldapMapping]) - for tmp,val in values_found: - if val.has_key(ldapMapping): - extraAttributes.append((ldapMapping,val[ldapMapping][0],[customattribute[module.property_descriptions[pname].short_description][0]])) - replaced = 1 - if len(val[ldapMapping]) > 1: - out.append("WARNING: singlevalue customattribute %s has more than one value set, replace first"%customattribute[module.property_descriptions[pname].short_description]) - if not replaced: - extraAttributes.append((ldapMapping,'',[customattribute[module.property_descriptions[pname].short_description][0]])) - if action in ['modify','edit','create','new']: - for i in customattribute.keys(): - if not i in customattributes_set: - out.append("WARNING: customattribute %s not found, value not set"%i) - if policy_reference: for el in policy_reference: oc = lo.get(el,['objectClass']) @@ -885,24 +817,6 @@ def _doit(arglist): out.append('E: circular group dependency detected: %s' % e) return out + ["OPERATION FAILED"] - if extraOC or extraAttributes: - if extraOC: - oc=lo.search(base=dn, scope='base', attr=['objectClass']) - - noc=[] - for i in range(len(oc[0][1]['objectClass'])): - noc.append(oc[0][1]['objectClass'][i]) - - for i in range(len(extraOC)): - if extraOC[i] not in noc: - noc.append(extraOC[i]) - - if oc != noc: - extraAttributes.append(('objectClass',oc,noc)) - - if extraAttributes: - lo.modify(dn,extraAttributes) - if policy_reference: lo.modify(dn,[('objectClass','','univentionPolicyReference')]) modlist=[] @@ -1010,52 +924,6 @@ def _doit(arglist): out.append('E: Invalid Syntax: %s' % e) return out + ["OPERATION FAILED"] - if extraOC or extraAttributes: - if extraOC: - oc=lo.search(base=dn, scope='base', attr=['objectClass']) - - noc=[] - for i in range(len(oc[0][1]['objectClass'])): - noc.append(oc[0][1]['objectClass'][i]) - - for i in range(len(extraOC)): - if not extraOC[i] in noc: - noc.append(extraOC[i]) - - if noc != oc[0][1]['objectClass']: - extraAttributes.append(('objectClass',oc[0][1]['objectClass'],noc)) - if extraAttributes: - try: - lo.modify(dn,extraAttributes) - object_modified+=1 - except univention.admin.uexceptions.ldapError, msg: - out.append("ldap Error: %s"%msg) - - if customattribute_remove: - extraAttributes=[] - removed_attributes=[] - if hasattr(module, 'ldap_extra_objectclasses'): - for oc, pname, syntax, ldapMapping, deleteValues, deleteObjectClass in module.ldap_extra_objectclasses: - for index in range(0,len(customattribute_remove)): - if customattribute_remove[index][0] == module.property_descriptions[pname].short_description: - for tmp,val in lo.search(base=dn, attr=[ldapMapping]): - if val.has_key(ldapMapping): - for i in range(0, len(val[ldapMapping])): - if (not customattribute_remove[index][1]) or customattribute_remove[index][1] == val[ldapMapping][i]: - extraAttributes.append((ldapMapping,val[ldapMapping][i],'')) - removed_attributes.append(module.property_descriptions[pname].short_description) - else: - out.append("customattribute %s not set"%module.property_descriptions[pname].short_description) - removed_attributes.append(module.property_descriptions[pname].short_description) - - if extraAttributes: - lo.modify(dn,extraAttributes) - object_modified+=1 - - for n,v in customattribute_remove: - if not n in removed_attributes: - out.append("WARNING: customattribute %s not found"%n) - if policy_reference: if 'univentionPolicyReference' not in lo.get(dn,['objectClass'])['objectClass']: lo.modify(dn,[('objectClass','','univentionPolicyReference')]) -- --- .../modules/univention/admincli/admin.py | 582 +++++++++++---------- .../univention-cli-server | 9 +- 2 files changed, 300 insertions(+), 291 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -30,7 +30,8 @@ # /usr/share/common-licenses/AGPL-3; if not, see # . - +from textwrap import dedent +import sys import getopt import re import string @@ -54,93 +55,92 @@ univention.admin.modules.update() # update choices-lists which are defined in LDAP univention.admin.syntax.update_choices() -# usage information -def usage(): - out=[] - out.append('univention-directory-manager: command line interface for managing UCS') - out.append('copyright (c) 2001-@%@copyright_lastyear@%@ Univention GmbH, Germany') - out.append('') - out.append('Syntax:') - out.append(' univention-directory-manager module action [options]') - out.append(' univention-directory-manager [--help] [--version]') - out.append('') - out.append('actions:') - out.append(' %-32s %s' % ('create:', 'Create a new object')) - out.append(' %-32s %s' % ('modify:', 'Modify an existing object')) - out.append(' %-32s %s' % ('remove:', 'Remove an existing object')) - out.append(' %-32s %s' % ('list:', 'List objects')) - out.append(' %-32s %s' % ('move:', 'Move object in directory tree')) - out.append('') - out.append(' %-32s %s' % ('-h | --help | -?:', 'print this usage message')) - out.append(' %-32s %s' % ('--version:', 'print version information')) - out.append('') - out.append('general options:') - out.append(' --%-30s %s' % ('logfile', 'path and name of the logfile to be used')) - out.append('') - out.append('create options:') - out.append(' --%-30s %s' % ('binddn', 'bind DN')) - out.append(' --%-30s %s' % ('bindpwd', 'bind password')) - out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) - out.append(' --%-30s %s' % ('position', 'Set position in tree')) - out.append(' --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar')) - out.append(' --%-30s %s' % ('superordinate', 'Use superordinate module')) - out.append(' --%-30s %s' % ('option', 'Use only given module options')) - out.append(' --%-30s %s' % ('policy-reference', 'Reference to policy given by DN')) - out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) - out.append(' --%-30s ' % ('ignore_exists')) - out.append('') - out.append('modify options:') - out.append(' --%-30s %s' % ('binddn', 'bind DN')) - out.append(' --%-30s %s' % ('bindpwd', 'bind password')) - out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) - out.append(' --%-30s %s' % ('dn', 'Edit object with DN')) - out.append(' --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar')) - out.append(' --%-30s %s' % ('append', 'Append value to variable, e.g. foo=bar')) - out.append(' --%-30s %s' % ('remove', 'Remove value from variable, e.g. foo=bar')) - out.append(' --%-30s %s' % ('option', 'Use only given module options')) - out.append(' --%-30s %s' % ('append-option', 'Append the module options')) - out.append(' --%-30s %s' % ('policy-reference', 'Reference to policy given by DN')) - out.append(' --%-30s %s' % ('policy-dereference', 'Remove reference to policy given by DN')) - out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) - out.append('') - out.append('remove options:') - out.append(' --%-30s %s' % ('binddn', 'bind DN')) - out.append(' --%-30s %s' % ('bindpwd', 'bind password')) - out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) - out.append(' --%-30s %s' % ('dn', 'Remove object with DN')) - out.append(' --%-30s %s' % ('superordinate', 'Use superordinate module')) - out.append(' --%-30s %s' % ('filter', 'Lookup filter e.g. foo=bar')) - out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) - out.append(' --%-30s %s' % ('remove_referring', 'remove referring objects')) - out.append('') - out.append('list options:') - out.append(' --%-30s %s' % ('filter', 'Lookup filter e.g. foo=bar')) - out.append(' --%-30s %s' % ('policies', 'List policy-based settings:')) - out.append(' %-30s %s' % ('', '0:short, 1:long (with policy-DN)')) - out.append('') - out.append('move options:') - out.append(' --%-30s %s' % ('binddn', 'bind DN')) - out.append(' --%-30s %s' % ('bindpwd', 'bind password')) - out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) - out.append(' --%-30s %s' % ('dn', 'Move object with DN')) - out.append(' --%-30s %s' % ('position', 'Move to position in tree')) - out.append('') - out.append('Description:') - out.append(' univention-directory-manager is a tool to handle the configuration for UCS') - out.append(' on command line level.') - out.append(' Use "univention-directory-manager modules" for a list of available modules.') - out.append('') - return out - -def version(): - o=[] - o.append('univention-directory-manager @%@package_version@%@') - return o - -def _print_property( module, action, name, output ): + +class Failed(Exception): + def __str__(self): + return "OPERATION FAILED" + + +def usage(out=sys.stdout): + print >> out, dedent("""\ + %(prog)s command line interface for managing UCS + copyright (c) 2001-%(year)s Univention GmbH, Germany + + Syntax: + %(prog)s module action [options] + %(prog)s [--help] [--version] + + actions: + create: Create a new object + modify: Modify an existing object + remove: Remove an existing object + list: List objects + move: Move object in directory tree + + -h | --help | -?: Print this usage message + --version: Print version information + + general options: + --logfile Path and name of the logfile to be used + --binddn Bind DN + --bindpwd Bind password + --bindpwdfile file containing bind password + --tls 0 (no); 1 (try); 2 (must) + + create options: + --position Set position in tree + --set Set variable to value, e.g. foo=bar + --superordinate Use superordinate module + --option Use only given module options + --policy-reference Reference to policy given by DN + --ignore_exists + + modify options: + --dn Edit object with DN + --set Set variable to value, e.g. foo=bar + --append Append value to variable, e.g. foo=bar + --remove Remove value from variable, e.g. foo=bar + --option Use only given module options + --append-option Append the module options + --policy-reference Reference to policy given by DN + --policy-dereference Remove reference to policy given by DN + + remove options: + --dn Remove object with DN + --superordinate Use superordinate module + --filter Lookup filter e.g. foo=bar + --remove_referring Remove referring objects + + list options: + --filter Lookup filter e.g. foo=bar + --policies List policy-based settings: + 0:short, 1:long (with policy-DN) + + move options: + --dn Move object with DN + --position Move to position in tree + + Description: + %(prog)s is a tool to handle the configuration for UCS + on command line level. + Use "%(prog)s modules" for a list of available modules. + """) % { + "prog": "univention-directory-manager", + "year": "@%@copyright_lastyear@%@", + } + + +def version(out=sys.stdout): + print >> out, 'univention-directory-manager @%@package_version@%@' + + +def _print_property(module, action, name, out=sys.stdout): property = module.property_descriptions.get( name ) if property is None: - output.append( 'E: unknown property %s of module %s' % ( name, univention.admin.modules.name( module ) ) ) + print >> out, 'E: unknown property %s of module %s' % ( + name, + univention.admin.modules.name(module), + ) return required = { @@ -181,32 +181,35 @@ def _print_property( module, action, name, output ): flags += ',' flags += '[]' if flags: - flags = '(' + flags + ')' + name += ' (%s)' % (flags,) + + print >> out, ' %-40s %s' % ( + name, + property.short_description + ) - output.append( ' %-40s %s' % ( name + ' ' + flags, property.short_description ) ) -def module_usage(information, action=''): - out=[] +def module_usage(information, action='', out=sys.stdout): for module, l in information.items(): properties, options = l if options: - out.append('') - out.append('%s options:' % module.module) + print >> out, '' + print >> out, '%s options:' % module.module for name, option in options.items(): - out.append(' %-32s %s' % (name, option.short_description)) + print >> out, ' %-32s %s' % (name, option.short_description) - out.append('') - out.append('%s variables:' % module.module) + print >> out, '' + print >> out, '%s variables:' % module.module if not hasattr(module,"layout"): continue for moduletab in module.layout: - out.append(' %s:' % (moduletab.label)) + print >> out, ' %s:' % (moduletab.label) for row in moduletab.layout: if isinstance( row, Group ): - out.append( ' %s' % row.label ) + print >> out, ' %s' % row.label for row in row.layout: if isinstance( row, basestring ): _print_property( module, action, row, out ) @@ -220,7 +223,6 @@ def module_usage(information, action=''): for item in row: _print_property( module, action, item, out ) - return out def module_information(module, identifies_only=0): information={module:[{},{}]} @@ -243,8 +245,7 @@ def _2utf8( text ): except: return text.decode( 'iso-8859-1' ) -def object_input(module, object, input, append=None, remove=None): - out=[] +def object_input(module, object, input, append=None, remove=None, out=sys.stdout): if append: for key, value in append.items(): if module.property_descriptions[key].syntax.name == 'file': @@ -256,7 +257,7 @@ def object_input(module, object, input, append=None, remove=None): object[key] = content fh.close() else: - out.append('WARNING: file not found: %s' % value) + print >> out, 'WARNING: file not found: %s' % value elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): for i in range(0,len(value)): @@ -272,7 +273,7 @@ def object_input(module, object, input, append=None, remove=None): if not object.has_key(key): object[key]=[] if val in object[key]: - out.append('WARNING: cannot append %s to %s, value exists'%(val,key)) + print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key) elif object[key] == [''] or object[key] == []: object[key]=[val] else: @@ -280,7 +281,7 @@ def object_input(module, object, input, append=None, remove=None): else: for val in value: if val in object[key]: - out.append('WARNING: cannot append %s to %s, value exists'%(val,key)) + print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key) elif object[key] == [''] or object[key] == []: object[key]=[val] else: @@ -289,7 +290,7 @@ def object_input(module, object, input, append=None, remove=None): tmp.append(val) object[key] = list(tmp) except univention.admin.uexceptions.valueInvalidSyntax, errmsg: - out.append('E: Invalid Syntax: %s' % str(errmsg)) + print >> out, 'E: Invalid Syntax: %s' % (errmsg,) if remove: for key, value in remove.items(): if univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): @@ -300,7 +301,7 @@ def object_input(module, object, input, append=None, remove=None): val=value[i].split(' ') else: val=[] - out.append('test_val=%s' % test_val) + print >> out, 'test_val=%s' % (test_val,) for j in test_val: if j and j.rstrip().lstrip(): val.append(j.rstrip().lstrip()) @@ -311,7 +312,7 @@ def object_input(module, object, input, append=None, remove=None): if val and val in object[key]: object[key].remove(val) else: - out.append("WARNING: cannot remove %s from %s, value does not exist"%(val,key)) + print >> out, "WARNING: cannot remove %s from %s, value does not exist" % (val, key) else: object[key]=[] @@ -326,7 +327,7 @@ def object_input(module, object, input, append=None, remove=None): if val in object[key]: object[key].remove(val) else: - out.append("WARNING: cannot remove %s from %s, value does not exist"%(val,key)) + print >> out, "WARNING: cannot remove %s from %s, value does not exist" % (val, key) if input: for key, value in input.items(): if module.property_descriptions[key].syntax.name == 'binaryfile': @@ -343,7 +344,7 @@ def object_input(module, object, input, append=None, remove=None): object[key]= content fh.close() else: - out.append('WARNING: file not found: %s' % value) + print >> out, 'WARNING: file not found: %s' % value elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): if type(value) == type([]): @@ -366,26 +367,24 @@ def object_input(module, object, input, append=None, remove=None): try: object[key]=value except univention.admin.uexceptions.ipOverridesNetwork, e: - out.append('WARNING: %s' % e.message) + print >> out, 'WARNING: %s' % e.message except univention.admin.uexceptions.valueMayNotChange, e: raise univention.admin.uexceptions.valueMayNotChange, "%s: %s"%(e.message, key) - return out -def list_available_modules(o=[]): - o.append("Available Modules are:") +def list_available_modules(out=sys.stdout): + print >> out, "Available Modules are:" avail_modules = [] for mod in univention.admin.modules.modules.keys(): avail_modules.append(mod) avail_modules.sort() for mod in avail_modules: - o.append(" %s"%mod) - return o + print >> out, " %s" % mod -def doit(arglist): - out=[] + +def doit(arglist, out=sys.stdout): try: - out=_doit(arglist) + _doit(arglist, out) except univention.admin.uexceptions.base, e: univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, traceback.format_exc()) @@ -406,26 +405,28 @@ def doit(arglist): msg[0] = '%s:' % msg[0].strip(':.') # append to the output - out.append(' '.join(msg)) - return out + ["OPERATION FAILED"] - return out + print >> out, ' '.join(msg) + print >> out, Failed() + except Failed as ex: + print >> out, ex -def _doit(arglist): - out=[] +def _doit(arglist, out=sys.stdout): # parse module and action + if set(arglist) & set(('-h', '--help', '-?')): + return usage(out=out) + + if '--version' in arglist: + return version(out=out) + if len(arglist) < 2: - return usage() + ["OPERATION FAILED"] + usage(out=out) + raise Failed() module_name=arglist[1] - if module_name in ['-h', '--help', '-?']: - return usage() - - if module_name == '--version': - return version() if module_name == 'modules': - return list_available_modules() + return list_available_modules(out=out) remove_referring=0 recursive=1 @@ -455,14 +456,13 @@ def _doit(arglist): try: opts, args=getopt.getopt(arglist[3:], '', longopts) except getopt.error, msg: - out.append(str(msg)) - return out + ["OPERATION FAILED"] + print >> out, msg + raise Failed() if not args == [] and type(args) == type([]): - msg = "WARNING: the following arguments are ignored:" - for argument in args: - msg = '%s "%s"' % (msg, argument) - out.append(msg) + print >> out, "WARNING: the following arguments are ignored: %s" % ( + " ".join(('"%s"' % _ for _ in args)), + ) position_dn='' dn='' @@ -503,8 +503,8 @@ def _doit(arglist): with open(val) as fp: bindpwd=fp.read().strip() except IOError as e: - out.append( 'E: could not read bindpwd from file (%s)' % str(e) ) - return out + ['OPERATION FAILED'] + print >> out, 'E: could not read bindpwd from file (%s)' % (e,) + raise Failed() elif opt == '--dn': dn = _2utf8( val ) elif opt == '--tls': @@ -527,7 +527,7 @@ def _doit(arglist): if logfile: univention.debug.init(logfile, 1, 0) else: - out.append("WARNING: no logfile specified") + print >> out, "WARNING: no logfile specified" configRegistry=univention.config_registry.ConfigRegistry() configRegistry.load() @@ -553,8 +553,8 @@ def _doit(arglist): lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, start_tls=tls, bindpw=bindpwd) except Exception, e: univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) - out.append('authentication error: %s' % str(e)) - return out + ["OPERATION FAILED"] + print >> out, 'authentication error: %s' % (e,) + raise Failed() policyOptions.extend(['-D', binddn, '-w', bindpwd]) ## FIXME not so nice else: @@ -568,12 +568,15 @@ def _doit(arglist): secretFileName='/etc/machine.secret' binddn=configRegistry['ldap/hostdn'] policyOptions.extend(['-D', binddn, '-y', secretFileName]) + else: + print >> out, "E: Missing LDAP credentials" + raise Failed() try: secretFile=open(secretFileName,'r') except IOError: - out.append('E: Permission denied, try --binddn and --bindpwd') - return out + ["OPERATION FAILED"] + print >> out, 'E: Permission denied, try --binddn and --bindpwd' + raise Failed() pwdLine=secretFile.readline() pwd=re.sub('\n','',pwdLine) @@ -581,8 +584,8 @@ def _doit(arglist): lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, bindpw=pwd, start_tls=tls) except Exception, e: univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) - out.append('authentication error: %s' % str(e)) - return out + ["OPERATION FAILED"] + print >> out, 'authentication error: %s' % (e,) + raise Failed() if not position_dn and superordinate_dn: position_dn=superordinate_dn @@ -593,20 +596,22 @@ def _doit(arglist): position=univention.admin.uldap.position(baseDN) position.setDn(position_dn) except univention.admin.uexceptions.noObject: - out.append('E: Invalid position') - return out + ["OPERATION FAILED"] + print >> out, 'E: Invalid position' + raise Failed() try: module=univention.admin.modules.get(module_name) except: - out.append("failed to get module %s."%module_name) - out.append("") - return list_available_modules(out) + ["OPERATION FAILED"] + print >> out, "failed to get module %s." % module_name + print >> out, "" + list_available_modules(out) + raise Failed() if not module: - out.append("unknown module %s." % module_name) - out.append("") - return list_available_modules(out) + ["OPERATION FAILED"] + print >> out, "unknown module %s." % module_name + print >> out, "" + list_available_modules(out) + raise Failed() # initialise modules univention.admin.modules.init(lo,position,module) @@ -617,21 +622,21 @@ def _doit(arglist): try: superordinate=univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn) except univention.admin.uexceptions.insufficientInformation, e: - out.append('Insufficient Information: %s' % str(e)) - return out + ["OPERATION FAILED"] + print >> out, 'Insufficient Information: %s' % (e,) + raise Failed() else: superordinate=None if len(arglist) == 2: - out = usage() + module_usage(information) - return out + ["OPERATION FAILED"] + module_usage(information, out=out) + raise Failed() action=arglist[2] if len(arglist) == 3 and action != 'list': - out = usage() + module_usage(information, action) - return out + ["OPERATION FAILED"] + module_usage(information, action, out=out) + raise Failed() for opt, val in opts: @@ -655,7 +660,7 @@ def _doit(arglist): was_set=1 if not was_set: - out.append("WARNING: No attribute with name '%s' in this module, value not set."%name) + print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name elif opt == '--append': pos=val.find('=') name=val[:pos] @@ -673,7 +678,7 @@ def _doit(arglist): append[name]=value was_set=1 if not was_set: - out.append("WARNING: No attribute with name %s in this module, value not appended."%name) + print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name elif opt == '--remove': pos=val.find('=') @@ -696,7 +701,7 @@ def _doit(arglist): remove[name]=value was_set=1 if not was_set: - out.append("WARNING: No attribute with name %s in this module, value not removed."%name) + print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name elif opt == '--remove_referring': remove_referring=1 elif opt == '--recursive': @@ -704,49 +709,48 @@ def _doit(arglist): if action in ['modify','edit','create','new']: - if policy_reference: for el in policy_reference: - oc = lo.get(el,['objectClass']) + oc = lo.get(el, ['objectClass']) if not oc: - out.append("Object to be referenced does not exist:"+el) - return out + ["OPERATION FAILED"] + print >> out, "Object to be referenced does not exist: %s" % (el,) + raise Failed() if not 'univentionPolicy' in oc['objectClass']: - out.append("Object to be referenced is no valid Policy:"+el) - return out + ["OPERATION FAILED"] + print >> out, "Object to be referenced is no valid Policy: %s" % (el,) + raise Failed() #+++# ACTION CREATE #+++# if action == 'create' or action == 'new': if hasattr(module,'operations') and module.operations: if not 'add' in module.operations: - out.append('Create %s not allowed' % module_name) - return out + ["OPERATION FAILED"] + print >> out, 'Create %s not allowed' % module_name + raise Failed() try: object=module.object(co, lo, position=position, superordinate=superordinate) except univention.admin.uexceptions.insufficientInformation: - out.append('E: Insufficient information') - out.append('Superordinate object is missing') - return out + ["OPERATION FAILED"] + print >> out, 'E: Insufficient information' + print >> out, 'Superordinate object is missing' + raise Failed() if parsed_options: object.options=parsed_options object.open() if hasattr(object,' open_warning') and object.open_warning: - out.append('WAR NING:%s'%object.open_warning) + print >> out, 'WARNING:%s' % object.open_warning exists=0 try: - out.extend(object_input(module, object, input, append=append)) + object_input(module, object, input, append=append, out=out) except univention.admin.uexceptions.nextFreeIp: if not ignore_exists: - out.append('E: No free IP address found') - return out + ['OPERATION FAILED'] + print >> out, 'E: No free IP address found' + raise Failed() except univention.admin.uexceptions.valueInvalidSyntax, err: - out.append('E: Invalid Syntax: %s' % err) - return out + ["OPERATION FAILED"] + print >> out, 'E: Invalid Syntax: %s' % err + raise Failed() except Exception, err: - out.append('E: Option %s is not valid' %err) - return out + ['OPERATION FAILED'] + print >> out, 'E: Option %s is not valid' % err + raise Failed() exists=0 exists_msg=None @@ -755,67 +759,67 @@ def _doit(arglist): except univention.admin.uexceptions.objectExists, dn: exists_msg = dn if not ignore_exists: - out.append('E: Object exists: %s' % exists_msg) - return out + ["OPERATION FAILED"] + print >> out, 'E: Object exists: %s' % exists_msg + raise Failed() else: exists=1 except univention.admin.uexceptions.uidAlreadyUsed, user: exists_msg = '(uid) %s' % user if not ignore_exists: - out.append('E: Object exists: %s' % exists_msg) - return out + ["OPERATION FAILED"] + print >> out, 'E: Object exists: %s' % exists_msg + raise Failed() else: exists=1 except univention.admin.uexceptions.groupNameAlreadyUsed, group: exists_msg = '(group) %s' % group if not ignore_exists: - out.append('E: Object exists: %s' % exists_msg) - return out + ["OPERATION FAILED"] + print >> out, 'E: Object exists: %s' % exists_msg + raise Failed() else: exists=1 except univention.admin.uexceptions.dhcpServerAlreadyUsed, name: exists_msg = '(dhcpserver) %s' % name if not ignore_exists: - out.append('E: Object exists: %s' % exists_msg) - return out + ["OPERATION FAILED"] + print >> out, 'E: Object exists: %s' % exists_msg + raise Failed() else: exists=1 except univention.admin.uexceptions.macAlreadyUsed, mac: exists_msg = '(mac) %s' % mac if not ignore_exists: - out.append('E: Object exists: %s' % exists_msg) - return out + ["OPERATION FAILED"] + print >> out, 'E: Object exists: %s' % exists_msg + raise Failed() else: exists=1 except univention.admin.uexceptions.noLock, e: exists_msg = '(nolock) %s' % str(e) if not ignore_exists: - out.append('E: Object exists: %s' % exists_msg) - return out + ["OPERATION FAILED"] + print >> out, 'E: Object exists: %s' % exists_msg + raise Failed() else: exists=1 except univention.admin.uexceptions.invalidDhcpEntry: - out.append('E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.') - return out + ["OPERATION FAILED"] + print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' + raise Failed() except univention.admin.uexceptions.invalidOptions, e: if not ignore_exists: - out.append('E: invalid Options: %s' % e) - return out + ["OPERATION FAILED"] + print >> out, 'E: invalid Options: %s' % e + raise Failed() except univention.admin.uexceptions.insufficientInformation: - out.append('E: Insufficient information') - out.append('The following parameters are missing:') + print >> out, 'E: Insufficient information' + print >> out, 'The following parameters are missing:' for i in module.property_descriptions: property=module.property_descriptions.get(i) if property.required: if not object.has_key(i) or (not object[i] or (type(object[i]) == list and object[i]==[''])): - out.append(i) - return out + ["OPERATION FAILED"] + print >> out, i + raise Failed() except univention.admin.uexceptions.noObject, e: - out.append('E: object not found: %s' % e) - return out + ["OPERATION FAILED"] + print >> out, 'E: object not found: %s' % e + raise Failed() except univention.admin.uexceptions.circularGroupDependency, e: - out.append('E: circular group dependency detected: %s' % e) - return out + ["OPERATION FAILED"] + print >> out, 'E: circular group dependency detected: %s' % e + raise Failed() if policy_reference: lo.modify(dn,[('objectClass','','univentionPolicyReference')]) @@ -826,44 +830,44 @@ def _doit(arglist): if exists == 1: if exists_msg: - out.append('Object exists: %s' % exists_msg) + print >> out, 'Object exists: %s' % exists_msg else: - out.append('Object exists') + print >> out, 'Object exists' else: if not dn: dn=object.dn - out.append('Object created: %s' % _2utf8( dn ) ) + print >> out, 'Object created: %s' % _2utf8(dn) #+++# ACTION MODIFY #+++# elif action == 'modify' or action == 'edit' or action == 'move': if not dn: - out.append('E: DN is missing') - return out + ["OPERATION FAILED"] + print >> out, 'E: DN is missing' + raise Failed() object_modified = 0 if hasattr(module,'operations') and module.operations: if not 'edit' in module.operations: - out.append('Modify %s not allowed' % module_name) - return out + ["OPERATION FAILED"] + print >> out, 'Modify %s not allowed' % module_name + raise Failed() try: object=univention.admin.objects.get(module, co, lo, position='', dn=dn) except univention.admin.uexceptions.noObject: - out.append('E: object not found') - return out + ["OPERATION FAILED"] + print >> out, 'E: object not found' + raise Failed() object.open() if hasattr(object,'open_warning') and object.open_warning: - out.append('WARNING:%s'%object.open_warning) + print >> out, 'WARNING:%s' % object.open_warning if action == 'move': if hasattr(module,'operations') and module.operations: if not 'move' in module.operations: - out.append('Move %s not allowed' % module_name) - return out + ["OPERATION FAILED"] + print >> out, 'Move %s not allowed' % module_name + raise Failed() if not position_dn: - out.append("need new position for moving object") + print >> out, "need new position for moving object" else: res = '' try: # check if global-position exists @@ -871,28 +875,28 @@ def _doit(arglist): except: pass if not res: - out.append("position does not exsist: %s"%position_dn) - return out + ["OPERATION FAILED"] + print >> out, "position does not exsist: %s" % position_dn + raise Failed() rdn = dn[:string.find(dn,',')] newdn="%s,%s" % (rdn,position_dn) try: object.move(newdn) object_modified+=1 except univention.admin.uexceptions.noObject: - out.append('E: object not found') - return out + ["OPERATION FAILED"] + print >> out, 'E: object not found' + raise Failed() except univention.admin.uexceptions.ldapError, msg: - out.append("ldap Error: %s"%msg) - return out + ["OPERATION FAILED"] + print >> out, "ldap Error: %s" % msg + raise Failed() except univention.admin.uexceptions.nextFreeIp: - out.append('E: No free IP address found') - return out + ['OPERATION FAILED'] + print >> out, 'E: No free IP address found' + raise Failed() except univention.admin.uexceptions.valueInvalidSyntax, err: - out.append('E: Invalid Syntax: %s' % err) - return out + ["OPERATION FAILED"] + print >> out, 'E: Invalid Syntax: %s' % err + raise Failed() except univention.admin.uexceptions.invalidOperation, msg: - out.append(str(msg)) - return out + ["OPERATION FAILED"] + print >> out, str(msg) + raise Failed() else: # modify @@ -903,26 +907,26 @@ def _doit(arglist): for option in parsed_append_options: object.options.append(option) try: - out.extend(object_input(module, object, input, append, remove)) + object_input(module, object, input, append, remove, out=out) except univention.admin.uexceptions.valueMayNotChange,e: - out.append(unicode(e[0])) - return out + ["OPERATION FAILED"] + print >> out, unicode(e[0]) + raise Failed() if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options: try: dn=object.modify() object_modified+=1 except univention.admin.uexceptions.noObject: - out.append('E: object not found') - return out + ["OPERATION FAILED"] + print >> out, 'E: object not found' + raise Failed() except univention.admin.uexceptions.invalidDhcpEntry: - out.append('E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.') - return out + ["OPERATION FAILED"] + print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' + raise Failed() except univention.admin.uexceptions.circularGroupDependency, e: - out.append('E: circular group dependency detected: %s' % e) - return out + ["OPERATION FAILED"] + print >> out, 'E: circular group dependency detected: %s' % e + raise Failed() except univention.admin.uexceptions.valueInvalidSyntax, e: - out.append('E: Invalid Syntax: %s' % e) - return out + ["OPERATION FAILED"] + print >> out, 'E: Invalid Syntax: %s' % e + raise Failed() if policy_reference: if 'univentionPolicyReference' not in lo.get(dn,['objectClass'])['objectClass']: @@ -934,7 +938,7 @@ def _doit(arglist): upr['univentionPolicyReference'] = [] for el in policy_reference: if val in upr['univentionPolicyReference']: - out.append('WARNING: cannot append %s to univentionPolicyReference, value exists' % val) + print >> out, 'WARNING: cannot append %s to univentionPolicyReference, value exists' % val else: modlist.append(('univentionPolicyReference','',el)) if modlist: @@ -949,16 +953,16 @@ def _doit(arglist): object_modified+=1 if object_modified > 0: - out.append( 'Object modified: %s'% _2utf8( dn ) ) + print >> out, 'Object modified: %s' % _2utf8(dn) else: - out.append( 'No modification: %s'% _2utf8( dn ) ) + print >> out, 'No modification: %s' % _2utf8(dn) elif action == 'remove' or action == 'delete': if hasattr(module,'operations') and module.operations: if not 'remove' in module.operations: - out.append('Remove %s not allowed' % module_name) - return out + ["OPERATION FAILED"] + print >> out, 'Remove %s not allowed' % module_name + raise Failed() try: if dn and filter: @@ -968,15 +972,15 @@ def _doit(arglist): elif filter: object=univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter, required=1, unique=1)[0] else: - out.append('E: dn or filter needed') - return out + ["OPERATION FAILED"] + print >> out, 'E: dn or filter needed' + raise Failed() except (univention.admin.uexceptions.noObject, IndexError): - out.append('E: object not found') - return out + ["OPERATION FAILED"] + print >> out, 'E: object not found' + raise Failed() object.open() if hasattr(object,'open_warning') and object.open_warning: - out.append('WARNING:%s'%object.open_warning) + print >> out, 'WARNING:%s' % object.open_warning if remove_referring and univention.admin.objects.wantsCleanup(object): univention.admin.objects.performCleanup(object) @@ -985,67 +989,69 @@ def _doit(arglist): try: object.remove(recursive) except univention.admin.uexceptions.ldapError,msg: - out.append(str(msg)) - return out + ["OPERATION FAILED"] + print >> out, str(msg) + raise Failed() else: try: object.remove() except univention.admin.uexceptions.primaryGroupUsed: - out.append('E: object in use') - return out + ["OPERATION FAILED"] - out.append( 'Object removed: %s'% _2utf8( dn ) ) + print >> out, 'E: object in use' + raise Failed() + print >> out, 'Object removed: %s' % _2utf8(dn) elif action == 'list' or action == 'lookup': if hasattr(module,'operations') and module.operations: if not 'search' in module.operations: - out.append('Search %s not allowed' % module_name) - return out + ["OPERATION FAILED"] + print >> out, 'Search %s not allowed' % module_name + raise Failed() - out.append( _2utf8( filter ) ) + print >> out, _2utf8(filter) try: for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter): - out.append( 'DN: %s' % _2utf8( univention.admin.objects.dn (object ) ) ) + print >> out, 'DN: %s' % _2utf8(univention.admin.objects.dn(object)) if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'): object.open() if hasattr(object,'open_warning') and object.open_warning: - out.append('WARNING: %s'%object.open_warning) + print >> out, 'WARNING: %s' % object.open_warning for key, value in object.items(): s=module.property_descriptions[key].syntax if module.property_descriptions[key].multivalue: for v in value: if s.tostring(v): - out.append(' %s: %s' % ( _2utf8( key ), _2utf8( s.tostring( v ) ) ) ) + print >> out, ' %s: %s' % (_2utf8(key), _2utf8(s.tostring(v))) else: - out.append(' %s: %s' % ( _2utf8( key ), None ) ) + print >> out, ' %s: %s' % (_2utf8(key), None) else: if s.tostring(value): - out.append(' %s: %s' % ( _2utf8( key ), _2utf8( s.tostring( value ) ) ) ) + print >> out, ' %s: %s' % (_2utf8(key), _2utf8(s.tostring(value))) else: - out.append(' %s: %s' % ( _2utf8( key ), None ) ) + print >> out, ' %s: %s' % (_2utf8(key), None) if 'univentionPolicyReference' in lo.get(univention.admin.objects.dn(object),['objectClass'])['objectClass']: references = lo.get( _2utf8(univention.admin.objects.dn( object ) ), [ 'univentionPolicyReference' ] ) if references: for el in references['univentionPolicyReference']: - out.append(' %s: %s' % ( 'univentionPolicyReference', - _2utf8( s.tostring( el ) ) ) ) + print >> out, ' %s: %s' % ( + 'univentionPolicyReference', + _2utf8(s.tostring(el)) + ) if list_policies: utf8_objectdn = _2utf8( univention.admin.objects.dn( object ) ) p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_objectdn], stdout=subprocess.PIPE) policyResults = p1.communicate()[0].split('\n') - out.append(" Policy-based Settings:") + print >> out, " Policy-based Settings:" policy='' value=[] client={} for line in policyResults: if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "): - out.append(" %s"%line.strip()) + print >> out, " %s" % line.strip() if policies_with_DN: clsplit=string.split(line.strip(), ': ') if clsplit[0] == 'Policy': @@ -1067,7 +1073,7 @@ def _doit(arglist): client[attribute]=[policy, value] value=[] - out.append('') + print >> out, '' if module_name == 'dhcp/host': subnet_module=univention.admin.modules.get('dhcp/subnet') @@ -1077,13 +1083,13 @@ def _doit(arglist): utf8_subnet_dn = _2utf8( subnet.dn ) p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_subnet_dn], stdout=subprocess.PIPE) policyResults = p1.communicate()[0].split('\n') - out.append(" Subnet-based Settings:") + print >> out, " Subnet-based Settings:" ddict={} policy='' value=[] for line in policyResults: if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "): - out.append(" %s"%line.strip()) + print >> out, " %s" % line.strip() if policies_with_DN: subsplit=string.split(line.strip(), ': ') if subsplit[0] == 'Policy': @@ -1101,13 +1107,12 @@ def _doit(arglist): ddict[subsplit[0]] = [] ddict[subsplit[0]].append(subsplit[1]) - out.append('') + print >> out, '' if policies_with_DN: ddict[attribute]=[policy, value] - value=[] - out.append(" Merged Settings:") + print >> out, " Merged Settings:" for key in ddict.keys(): if not client.has_key(key): @@ -1115,27 +1120,24 @@ def _doit(arglist): if policies_with_DN: for key in client.keys(): - out.append(" Policy: "+client[key][0]) - out.append(" Attribute: "+key) + print >> out, " Policy: " + client[key][0] + print >> out, " Attribute: " + key for i in range(0, len(client[key][1])): - out.append(" Value: "+client[key][1][i]) + print >> out, " Value: " + client[key][1][i] else: for key in client.keys(): for i in range(0, len(client[key])): - out.append(" %s=%s" % (key, client[key][i])) - out.append('') + print >> out, " %s=%s" % (key, client[key][i]) + print >> out, '' - out.append('') + print >> out, '' except univention.admin.uexceptions.ldapError, errmsg: - out.append('%s' %str(errmsg)) - return out + ["OPERATION FAILED"] + print >> out, '%s' % (errmsg,) + raise Failed() except univention.admin.uexceptions.valueInvalidSyntax, errmsg: - out.append('%s' %str(errmsg.message)) - return out + ["OPERATION FAILED"] + print >> out, '%s' % (errmsg.message,) + raise Failed() else: - out.append("Unknown or no action defined") - out.append('') - usage() - return out + ["OPERATION FAILED"] - - return out # nearly the only successfull return + print >> out, "Unknown or no action defined" + print >> out, '' + raise Failed() --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server @@ -48,6 +48,10 @@ try: licenseImportError = False except ImportError: licenseImportError = True +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO logfile = '' @@ -219,7 +223,10 @@ def doit(sarglist, conn): if cmdfile in ('univention-admin', 'univention-directory-manager', 'udm'): ud.debug(ud.ADMIN, ud.PROCESS, 'daemon [%s] [%s] Calling univention-directory-manager' % (os.getppid(), os.getpid())) ud.debug(ud.ADMIN, ud.ALL, 'daemon [%s] [%s] arglist: %s' % (os.getppid(), os.getpid(), arglist)) - output = univention.admincli.admin.doit(arglist) + stream = StringIO() + univention.admincli.admin.doit(arglist, stream) + value = stream.getvalue() + output = value.splitlines() elif cmdfile == 'univention-passwd': ud.debug(ud.ADMIN, ud.PROCESS, 'daemon [%s] [%s] Calling univention-passwd' % (os.getppid(), os.getpid())) ud.debug(ud.ADMIN, ud.ALL, 'daemon [%s] [%s] arglist: %s' % (os.getppid(), os.getpid(), arglist)) -- --- .../modules/univention/admincli/admin.py | 5 +++++ 1 file changed, 5 insertions(+) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -1141,3 +1141,8 @@ def _doit(arglist, out=sys.stdout): print >> out, "Unknown or no action defined" print >> out, '' raise Failed() + + +if __name__ == '__main__': + import sys + doit(sys.argv, sys.stdout) -- --- .../modules/univention/admincli/admin.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -267,8 +267,9 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout else: val=[] for j in test_val: - if j and j.rstrip().lstrip(): - val.append(j.rstrip().lstrip()) + j = j.strip() + if j: + val.append(j) if not object.has_key(key): object[key]=[] @@ -303,8 +304,9 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout val=[] print >> out, 'test_val=%s' % (test_val,) for j in test_val: - if j and j.rstrip().lstrip(): - val.append(j.rstrip().lstrip()) + j = j.strip() + if j: + val.append(j) for j in range(0,len(val)): val[j]='"%s"' % val[j] @@ -355,8 +357,9 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout else: val=[] for j in test_val: - if j and j.rstrip().lstrip(): - val.append(j.rstrip().lstrip()) + j = j.strip() + if j: + val.append(j) else: val=value.split(' ') if module.property_descriptions[key].multivalue: -- --- .../univention-cli-server | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server @@ -60,15 +60,10 @@ class MyRequestHandler(SocketServer.BaseRequestHandler): def handle(self): ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] new connection [%s]' % (os.getppid(), os.getpid())) sarglist = '' - while True: + while not sarglist.endswith('\0'): buf = self.request.recv(1024) - if buf[-1] == '\0': - buf = buf[:-1] - sarglist += buf - break - else: - sarglist += buf - doit(sarglist, self.request) + sarglist += buf + doit(sarglist.rstrip('\0'), self.request) ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] connection closed [%s]' % (os.getppid(), os.getpid())) def finish(self): -- --- .../modules/univention/admincli/admin.py | 9 +++------ .../univention-directory-manager-modules/univention-cli-server | 10 +++++----- 2 files changed, 8 insertions(+), 11 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -542,13 +542,10 @@ def _doit(arglist, out=sys.stdout): baseDN=configRegistry['ldap/base'] - if configRegistry.has_key('directory/manager/cmd/debug/level'): - debug_level=configRegistry['directory/manager/cmd/debug/level'] - else: - debug_level=0 + debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 0)) - univention.debug.set_level(univention.debug.LDAP, int(debug_level)) - univention.debug.set_level(univention.debug.ADMIN, int(debug_level)) + univention.debug.set_level(univention.debug.LDAP, debug_level) + univention.debug.set_level(univention.debug.ADMIN, debug_level) if binddn and bindpwd: univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using %s account" % binddn) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server @@ -114,8 +114,8 @@ def server_main(): configRegistry = ConfigRegistry() configRegistry.load() - debug_level = configRegistry.get('directory/manager/cmd/debug/level', 1) - ud.set_level(ud.ADMIN, int(debug_level)) + debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 1)) + ud.set_level(ud.ADMIN, debug_level) ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] forked to background' % os.getpid()) try: @@ -128,9 +128,9 @@ def server_main(): else: print >> sys.stderr, 'E: socket directory exists (%s)' % socket_dir - timeout = configRegistry.get('directory/manager/cmd/timeout') + timeout = float(configRegistry.get('directory/manager/cmd/timeout')) if timeout: - if int(timeout) > 2147483647: + if timeout > 2147483647: timeout = 2147483647 else: timeout = 300 @@ -154,7 +154,7 @@ def server_main(): try: while True: - rlist, _wlist, _xlist = select([sock], [], [], float(timeout)) + rlist, _wlist, _xlist = select([sock], [], [], timeout) for handler in rlist: handler.handle_request() if not rlist: -- --- .../univention-directory-manager-modules/univention-cli-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server @@ -91,7 +91,7 @@ def server_main(): socket_dir = '/tmp/admincli_%s/' % os.getuid() socket_filename = 'sock' - socket_path = (socket_dir+socket_filename) + socket_path = os.path.join(socket_dir, socket_filename) ud.init(logfile, ud.FLUSH, ud.NO_FUNCTION) -- --- .../modules/univention/admincli/admin.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -250,12 +250,8 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout for key, value in append.items(): if module.property_descriptions[key].syntax.name == 'file': if os.path.exists(value): - fh = open(value, 'r') - content='' - for line in fh.readlines(): - content += line - object[key] = content - fh.close() + with open(value, 'r') as fh: + object[key] = fh.read() else: print >> out, 'WARNING: file not found: %s' % value -- --- .../modules/univention/admincli/admin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -315,10 +315,10 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout object[key]=[] else: - if type(object[key]) is str: + if isinstance(object[key], basestring): object[key] = [ object[key] ] vallist = value - if type(value) is str: + if isinstance(value, basestring): vallist = [ value ] for val in vallist: @@ -345,7 +345,7 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout print >> out, 'WARNING: file not found: %s' % value elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): - if type(value) == type([]): + if isinstance(value, list): for i in range(0,len(value)): test_val=value[i].split('"') if test_val[0] and test_val[0] == value[i]: @@ -458,7 +458,7 @@ def _doit(arglist, out=sys.stdout): print >> out, msg raise Failed() - if not args == [] and type(args) == type([]): + if args and isinstance(args, list): print >> out, "WARNING: the following arguments are ignored: %s" % ( " ".join(('"%s"' % _ for _ in args)), ) @@ -807,7 +807,7 @@ def _doit(arglist, out=sys.stdout): for i in module.property_descriptions: property=module.property_descriptions.get(i) if property.required: - if not object.has_key(i) or (not object[i] or (type(object[i]) == list and object[i]==[''])): + if not object.has_key(i) or (not object[i] or (isinstance(object[i], list) and object[i]==[''])): print >> out, i raise Failed() except univention.admin.uexceptions.noObject, e: -- --- .../modules/univention/admincli/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -242,7 +242,7 @@ def module_information(module, identifies_only=0): def _2utf8( text ): try: return text.encode( 'utf-8' ) - except: + except UnicodeError: return text.decode( 'iso-8859-1' ) def object_input(module, object, input, append=None, remove=None, out=sys.stdout): -- --- .../modules/univention/admincli/admin.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -373,9 +373,7 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout def list_available_modules(out=sys.stdout): print >> out, "Available Modules are:" - avail_modules = [] - for mod in univention.admin.modules.modules.keys(): - avail_modules.append(mod) + avail_modules = univention.admin.modules.modules.keys() avail_modules.sort() for mod in avail_modules: print >> out, " %s" % mod -- --- .../modules/univention/admincli/admin.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -226,7 +226,7 @@ def module_usage(information, action='', out=sys.stdout): def module_information(module, identifies_only=0): information={module:[{},{}]} - if 'superordinate' in dir(module) and module.superordinate: + if getattr(module, 'superordinate', None): superordinate=univention.admin.modules.get(module.superordinate) information.update(module_information(superordinate, identifies_only=1)) @@ -715,7 +715,7 @@ def _doit(arglist, out=sys.stdout): #+++# ACTION CREATE #+++# if action == 'create' or action == 'new': - if hasattr(module,'operations') and module.operations: + if getattr(module, 'operations', None): if not 'add' in module.operations: print >> out, 'Create %s not allowed' % module_name raise Failed() @@ -730,7 +730,7 @@ def _doit(arglist, out=sys.stdout): object.options=parsed_options object.open() - if hasattr(object,' open_warning') and object.open_warning: + if getattr(object, 'open_warning', None): print >> out, 'WARNING:%s' % object.open_warning exists=0 try: @@ -840,7 +840,7 @@ def _doit(arglist, out=sys.stdout): object_modified = 0 - if hasattr(module,'operations') and module.operations: + if getattr(module, 'operations', None): if not 'edit' in module.operations: print >> out, 'Modify %s not allowed' % module_name raise Failed() @@ -852,11 +852,11 @@ def _doit(arglist, out=sys.stdout): raise Failed() object.open() - if hasattr(object,'open_warning') and object.open_warning: + if getattr(object, 'open_warning', None): print >> out, 'WARNING:%s' % object.open_warning if action == 'move': - if hasattr(module,'operations') and module.operations: + if getattr(module, 'operations', None): if not 'move' in module.operations: print >> out, 'Move %s not allowed' % module_name raise Failed() @@ -953,7 +953,7 @@ def _doit(arglist, out=sys.stdout): elif action == 'remove' or action == 'delete': - if hasattr(module,'operations') and module.operations: + if getattr(module, 'operations', None): if not 'remove' in module.operations: print >> out, 'Remove %s not allowed' % module_name raise Failed() @@ -973,7 +973,7 @@ def _doit(arglist, out=sys.stdout): raise Failed() object.open() - if hasattr(object,'open_warning') and object.open_warning: + if getattr(object, 'open_warning', None): print >> out, 'WARNING:%s' % object.open_warning if remove_referring and univention.admin.objects.wantsCleanup(object): @@ -995,7 +995,7 @@ def _doit(arglist, out=sys.stdout): elif action == 'list' or action == 'lookup': - if hasattr(module,'operations') and module.operations: + if getattr(module, 'operations', None): if not 'search' in module.operations: print >> out, 'Search %s not allowed' % module_name raise Failed() @@ -1006,9 +1006,9 @@ def _doit(arglist, out=sys.stdout): for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter): print >> out, 'DN: %s' % _2utf8(univention.admin.objects.dn(object)) - if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'): + if not getattr(module, 'virtual', None): object.open() - if hasattr(object,'open_warning') and object.open_warning: + if getattr(object, 'open_warning', None): print >> out, 'WARNING: %s' % object.open_warning for key, value in object.items(): s=module.property_descriptions[key].syntax -- --- .../modules/univention/admincli/admin.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -529,7 +529,7 @@ def _doit(arglist, out=sys.stdout): configRegistry=univention.config_registry.ConfigRegistry() configRegistry.load() - if configRegistry.has_key('ldap/master') and configRegistry['ldap/master']: + if configRegistry.get('ldap/master'): co=univention.admin.config.config(configRegistry['ldap/master']) else: co=univention.admin.config.config() @@ -641,7 +641,7 @@ def _doit(arglist, out=sys.stdout): was_set=0 for mod, (properties,options) in information.items(): - if properties.has_key(name): + if name in properties: if properties[name].multivalue: if not input.has_key(name): input[name]=[] @@ -661,7 +661,7 @@ def _doit(arglist, out=sys.stdout): value = _2utf8( val[ pos + 1 : ] ) was_set=0 for mod, (properties,options) in information.items(): - if properties.has_key(name): + if name in properties: if properties[name].multivalue: if not append.has_key(name): append[name]=[] @@ -684,7 +684,7 @@ def _doit(arglist, out=sys.stdout): value = _2utf8( val[ pos + 1 : ] ) was_set=0 for mod, (properties,options) in information.items(): - if properties.has_key(name): + if name in properties: if properties[name].multivalue: if not remove.has_key(name): remove[name]=[] @@ -805,7 +805,7 @@ def _doit(arglist, out=sys.stdout): for i in module.property_descriptions: property=module.property_descriptions.get(i) if property.required: - if not object.has_key(i) or (not object[i] or (isinstance(object[i], list) and object[i]==[''])): + if i not in object or (not object[i] or (isinstance(object[i], list) and object[i]==[''])): print >> out, i raise Failed() except univention.admin.uexceptions.noObject, e: @@ -928,7 +928,7 @@ def _doit(arglist, out=sys.stdout): object_modified+=1 modlist=[] upr = lo.search(base=dn, scope='base', attr=['univentionPolicyReference'])[0][1] - if not upr.has_key('univentionPolicyReference'): + if 'univentionPolicyReference' not in upr: upr['univentionPolicyReference'] = [] for el in policy_reference: if val in upr['univentionPolicyReference']: @@ -1109,7 +1109,7 @@ def _doit(arglist, out=sys.stdout): print >> out, " Merged Settings:" for key in ddict.keys(): - if not client.has_key(key): + if key not in client: client[key]=ddict[key] if policies_with_DN: -- --- .../modules/univention/admincli/admin.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -639,27 +639,22 @@ def _doit(arglist, out=sys.stdout): name=val[:pos] value = _2utf8( val[ pos + 1 : ] ) - was_set=0 for mod, (properties,options) in information.items(): if name in properties: if properties[name].multivalue: if not input.has_key(name): input[name]=[] - was_set=1 if value: input[name].append(value) - was_set=1 else: input[name]=value - was_set=1 - - if not was_set: + break + else: print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name elif opt == '--append': pos=val.find('=') name=val[:pos] value = _2utf8( val[ pos + 1 : ] ) - was_set=0 for mod, (properties,options) in information.items(): if name in properties: if properties[name].multivalue: @@ -667,11 +662,10 @@ def _doit(arglist, out=sys.stdout): append[name]=[] if value: append[name].append(value) - was_set=1 else: append[name]=value - was_set=1 - if not was_set: + break + else: print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name elif opt == '--remove': @@ -682,7 +676,6 @@ def _doit(arglist, out=sys.stdout): else: name=val[:pos] value = _2utf8( val[ pos + 1 : ] ) - was_set=0 for mod, (properties,options) in information.items(): if name in properties: if properties[name].multivalue: @@ -690,11 +683,10 @@ def _doit(arglist, out=sys.stdout): remove[name]=[] if value: remove[name].append(value) - was_set=1 else: remove[name]=value - was_set=1 - if not was_set: + break + else: print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name elif opt == '--remove_referring': remove_referring=1 -- --- .../modules/univention/admincli/admin.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -642,10 +642,9 @@ def _doit(arglist, out=sys.stdout): for mod, (properties,options) in information.items(): if name in properties: if properties[name].multivalue: - if not input.has_key(name): - input[name]=[] + values = input.setdefault(name, []) if value: - input[name].append(value) + values.append(value) else: input[name]=value break @@ -658,10 +657,9 @@ def _doit(arglist, out=sys.stdout): for mod, (properties,options) in information.items(): if name in properties: if properties[name].multivalue: - if not append.has_key(name): - append[name]=[] + values = append.setdefault(name, []) if value: - append[name].append(value) + values.append(value) else: append[name]=value break @@ -679,10 +677,9 @@ def _doit(arglist, out=sys.stdout): for mod, (properties,options) in information.items(): if name in properties: if properties[name].multivalue: - if not remove.has_key(name): - remove[name]=[] + values = remove.setdefault(name, []) if value: - remove[name].append(value) + values.append(value) else: remove[name]=value break -- --- .../modules/univention/admincli/admin.py | 58 +++++++++++----------- 1 file changed, 29 insertions(+), 29 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -256,10 +256,10 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout print >> out, 'WARNING: file not found: %s' % value elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): - for i in range(0,len(value)): - test_val=value[i].split('"') - if test_val[0] and test_val[0] == value[i]: - val=value[i].split(' ') + for i in value: + test_val = i.split('"') + if test_val[0] and test_val[0] == i: + val = i.split(' ') else: val=[] for j in test_val: @@ -267,23 +267,23 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout if j: val.append(j) - if not object.has_key(key): - object[key]=[] - if val in object[key]: + values = object.setdefault(key, []) + if val in values: print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key) - elif object[key] == [''] or object[key] == []: - object[key]=[val] + elif values == [''] or values == []: + values[:] = [val] else: - object[key].append(val) + values.append(val) else: for val in value: - if val in object[key]: + values = object[key] + if val in values: print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key) - elif object[key] == [''] or object[key] == []: - object[key]=[val] + elif values == [''] or values == []: + values[:] = [val] else: try: - tmp = list(object[key]) + tmp = list(values) tmp.append(val) object[key] = list(tmp) except univention.admin.uexceptions.valueInvalidSyntax, errmsg: @@ -292,10 +292,10 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout for key, value in remove.items(): if univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): if value: - for i in range(0,len(value)): - test_val=value[i].split('"') - if test_val[0] and test_val[0] == value[i]: - val=value[i].split(' ') + for i in value: + test_val = i.split('"') + if test_val[0] and test_val[0] == i: + val = i.split(' ') else: val=[] print >> out, 'test_val=%s' % (test_val,) @@ -346,8 +346,8 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): if isinstance(value, list): - for i in range(0,len(value)): - test_val=value[i].split('"') + for i in value: + test_val = i.split('"') if test_val[0] and test_val[0] == value[i]: val=value[i].split(' ') else: @@ -1097,20 +1097,20 @@ def _doit(arglist, out=sys.stdout): print >> out, " Merged Settings:" - for key in ddict.keys(): + for key, values in ddict.items(): if key not in client: - client[key]=ddict[key] + client[key] = values if policies_with_DN: - for key in client.keys(): - print >> out, " Policy: " + client[key][0] + for key, (policy, values) in client.items(): + print >> out, " Policy: " + policy print >> out, " Attribute: " + key - for i in range(0, len(client[key][1])): - print >> out, " Value: " + client[key][1][i] + for value in values: + print >> out, " Value: " + value else: - for key in client.keys(): - for i in range(0, len(client[key])): - print >> out, " %s=%s" % (key, client[key][i]) + for key, values in client.items(): + for value in values: + print >> out, " %s=%s" % (key, value) print >> out, '' print >> out, '' -- --- .../modules/univention/admincli/admin.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -304,8 +304,7 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout if j: val.append(j) - for j in range(0,len(val)): - val[j]='"%s"' % val[j] + val = ['"%s"' % _ for _ in val] if val and val in object[key]: object[key].remove(val) @@ -395,7 +394,7 @@ def doit(arglist, out=sys.stdout): msg.extend(e.args) # strip elements and make sure that a ':' is printed iff further information follows - msg = [i.strip() for i in msg] + msg = [_.strip() for _ in msg] if len(msg) == 1: msg[0] = '%s.' % msg[0].strip(':.') elif len(msg) > 1: @@ -806,9 +805,7 @@ def _doit(arglist, out=sys.stdout): if policy_reference: lo.modify(dn,[('objectClass','','univentionPolicyReference')]) - modlist=[] - for el in policy_reference: - modlist.append(('univentionPolicyReference','',el)) + modlist = [('univentionPolicyReference', '', el) for el in policy_reference] lo.modify(dn,modlist) if exists == 1: @@ -929,9 +926,7 @@ def _doit(arglist, out=sys.stdout): object_modified+=1 if policy_dereference: - modlist=[] - for el in policy_dereference: - modlist.append(('univentionPolicyReference',el,'')) + modlist = [('univentionPolicyReference', el, '') for el in policy_dereference] lo.modify(dn,modlist) object_modified+=1 -- --- .../modules/univention/admincli/admin.py | 35 ++++++---------------- 1 file changed, 9 insertions(+), 26 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -224,11 +224,11 @@ def module_usage(information, action='', out=sys.stdout): _print_property( module, action, item, out ) -def module_information(module, identifies_only=0): +def module_information(module, identifies_only=False): information={module:[{},{}]} if getattr(module, 'superordinate', None): superordinate=univention.admin.modules.get(module.superordinate) - information.update(module_information(superordinate, identifies_only=1)) + information.update(module_information(superordinate, identifies_only=True)) if not identifies_only: for name, property in module.property_descriptions.items(): @@ -424,8 +424,8 @@ def _doit(arglist, out=sys.stdout): if module_name == 'modules': return list_available_modules(out=out) - remove_referring=0 - recursive=1 + remove_referring = False + recursive = True # BUG: if this is the default, there's no way to disable it # parse options longopts = [ 'position=', @@ -469,7 +469,7 @@ def _doit(arglist, out=sys.stdout): policyOptions=[] logfile='/var/log/univention/directory-manager-cmd.log' tls=2 - ignore_exists=0 + ignore_exists = False superordinate_dn='' parsed_append_options=[] parsed_options=[] @@ -506,7 +506,7 @@ def _doit(arglist, out=sys.stdout): elif opt == '--tls': tls=val elif opt == '--ignore_exists': - ignore_exists=1 + ignore_exists = True elif opt == '--superordinate': superordinate_dn=val elif opt == '--option': @@ -685,9 +685,9 @@ def _doit(arglist, out=sys.stdout): else: print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name elif opt == '--remove_referring': - remove_referring=1 + remove_referring = True elif opt == '--recursive': - recursive=1 + recursive = True if action in ['modify','edit','create','new']: @@ -720,7 +720,6 @@ def _doit(arglist, out=sys.stdout): object.open() if getattr(object, 'open_warning', None): print >> out, 'WARNING:%s' % object.open_warning - exists=0 try: object_input(module, object, input, append=append, out=out) except univention.admin.uexceptions.nextFreeIp: @@ -734,7 +733,6 @@ def _doit(arglist, out=sys.stdout): print >> out, 'E: Option %s is not valid' % err raise Failed() - exists=0 exists_msg=None try: dn=object.create() @@ -743,43 +741,31 @@ def _doit(arglist, out=sys.stdout): if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - else: - exists=1 except univention.admin.uexceptions.uidAlreadyUsed, user: exists_msg = '(uid) %s' % user if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - else: - exists=1 except univention.admin.uexceptions.groupNameAlreadyUsed, group: exists_msg = '(group) %s' % group if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - else: - exists=1 except univention.admin.uexceptions.dhcpServerAlreadyUsed, name: exists_msg = '(dhcpserver) %s' % name if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - else: - exists=1 except univention.admin.uexceptions.macAlreadyUsed, mac: exists_msg = '(mac) %s' % mac if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - else: - exists=1 except univention.admin.uexceptions.noLock, e: exists_msg = '(nolock) %s' % str(e) if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - else: - exists=1 except univention.admin.uexceptions.invalidDhcpEntry: print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' raise Failed() @@ -808,11 +794,8 @@ def _doit(arglist, out=sys.stdout): modlist = [('univentionPolicyReference', '', el) for el in policy_reference] lo.modify(dn,modlist) - if exists == 1: - if exists_msg: + if exists_msg: print >> out, 'Object exists: %s' % exists_msg - else: - print >> out, 'Object exists' else: if not dn: dn=object.dn -- --- .../modules/univention/admincli/admin.py | 98 +++++++++------------- 1 file changed, 40 insertions(+), 58 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -407,6 +407,44 @@ def doit(arglist, out=sys.stdout): print >> out, ex +def get_policy(dn, out=sys.stdout, policyOptions=None, policies_with_DN=False): + cmd = ['univention_policy_result'] + if policyOptions: + cmd.extend(policyOptions) + cmd.append(dn) + + policy = attribute = '' + value = [] + client = {} + + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) + for line in proc.stdout: + line = line.strip() + if not line or line.startswith("DN: ") or line.startswith("POLICY "): + continue + + print >> out, " %s" % line + if policies_with_DN: + key, val = line.split(': ', 1) + if key == 'Policy': + if attribute and policy: + client[attribute] = [policy, value] + value = [] + policy = val + elif key == 'Attribute': + attribute = val + elif key == 'Value': + value.append(val) + else: + key, val = line.split('=', 1) + client.setdefault(key, []).append(val) + proc.wait() + if policies_with_DN and attribute and policy: + client[attribute] = [policy, value] + + return client + + def _doit(arglist, out=sys.stdout): # parse module and action if set(arglist) & set(('-h', '--help', '-?')): @@ -1003,37 +1041,8 @@ def _doit(arglist, out=sys.stdout): if list_policies: utf8_objectdn = _2utf8( univention.admin.objects.dn( object ) ) - p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_objectdn], stdout=subprocess.PIPE) - policyResults = p1.communicate()[0].split('\n') - print >> out, " Policy-based Settings:" - policy='' - value=[] - client={} - for line in policyResults: - if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "): - print >> out, " %s" % line.strip() - if policies_with_DN: - clsplit=string.split(line.strip(), ': ') - if clsplit[0] == 'Policy': - if policy: - client[attribute]=[policy, value] - value=[] - policy=clsplit[1] - elif clsplit[0] == 'Attribute': - attribute=clsplit[1] - elif clsplit[0] == 'Value': - value.append(clsplit[1]) - else: - clsplit=string.split(line.strip(), '=') - if not client.has_key(clsplit[0]): - client[clsplit[0]] = [] - client[clsplit[0]].append(clsplit[1]) - - if policies_with_DN: - client[attribute]=[policy, value] - value=[] - + client = get_policy(utf8_objectdn, out, policyOptions, policies_with_DN) print >> out, '' if module_name == 'dhcp/host': @@ -1042,37 +1051,10 @@ def _doit(arglist, out=sys.stdout): if univention.admin.ipaddress.ip_is_in_network(subnet['subnet'], subnet['subnetmask'], object['fixedaddress'][0]): utf8_subnet_dn = _2utf8( subnet.dn ) - p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_subnet_dn], stdout=subprocess.PIPE) - policyResults = p1.communicate()[0].split('\n') print >> out, " Subnet-based Settings:" - ddict={} - policy='' - value=[] - for line in policyResults: - if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "): - print >> out, " %s" % line.strip() - if policies_with_DN: - subsplit=string.split(line.strip(), ': ') - if subsplit[0] == 'Policy': - if policy: - ddict[attribute]=[policy, value] - value=[] - policy=subsplit[1] - elif subsplit[0] == 'Attribute': - attribute=subsplit[1] - elif subsplit[0] == 'Value': - value.append(subsplit[1]) - else: - subsplit=string.split(line.strip(), '=') - if not ddict.has_key(subsplit[0]): - ddict[subsplit[0]] = [] - ddict[subsplit[0]].append(subsplit[1]) - + ddict = get_policy(utf8_subnet_dn, out, policyOptions, policies_with_DN) print >> out, '' - if policies_with_DN: - ddict[attribute]=[policy, value] - print >> out, " Merged Settings:" for key, values in ddict.items(): -- --- .../modules/univention/admincli/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -46,7 +46,7 @@ import univention.admin.uexceptions import univention.admin.uldap import univention.admin.modules import univention.admin.objects -from univention.admin.layout import Tab, Group +from univention.admin.layout import Group import univention.config_registry import univention.admin.ipaddress -- --- .../modules/univention/admincli/admin.py | 100 ++++++++++----------- 1 file changed, 50 insertions(+), 50 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -40,14 +40,14 @@ import os import subprocess import traceback -import univention.debug +import univention.debug as ud -import univention.admin.uexceptions +import univention.admin.uexceptions as uex import univention.admin.uldap import univention.admin.modules import univention.admin.objects from univention.admin.layout import Group -import univention.config_registry +from univention.config_registry import ConfigRegistry import univention.admin.ipaddress univention.admin.modules.update() @@ -286,7 +286,7 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout tmp = list(values) tmp.append(val) object[key] = list(tmp) - except univention.admin.uexceptions.valueInvalidSyntax, errmsg: + except uex.valueInvalidSyntax, errmsg: print >> out, 'E: Invalid Syntax: %s' % (errmsg,) if remove: for key, value in remove.items(): @@ -364,10 +364,10 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout else: try: object[key]=value - except univention.admin.uexceptions.ipOverridesNetwork, e: + except uex.ipOverridesNetwork, e: print >> out, 'WARNING: %s' % e.message - except univention.admin.uexceptions.valueMayNotChange, e: - raise univention.admin.uexceptions.valueMayNotChange, "%s: %s"%(e.message, key) + except uex.valueMayNotChange, e: + raise uex.valueMayNotChange, "%s: %s"%(e.message, key) def list_available_modules(out=sys.stdout): @@ -381,8 +381,8 @@ def list_available_modules(out=sys.stdout): def doit(arglist, out=sys.stdout): try: _doit(arglist, out) - except univention.admin.uexceptions.base, e: - univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, traceback.format_exc()) + except uex.base, e: + ud.debug(ud.ADMIN, ud.WARN, traceback.format_exc()) # collect error information msg = [] @@ -559,11 +559,11 @@ def _doit(arglist, out=sys.stdout): policy_dereference.append(val) if logfile: - univention.debug.init(logfile, 1, 0) + ud.init(logfile, 1, 0) else: print >> out, "WARNING: no logfile specified" - configRegistry=univention.config_registry.ConfigRegistry() + configRegistry = ConfigRegistry() configRegistry.load() if configRegistry.get('ldap/master'): @@ -575,27 +575,27 @@ def _doit(arglist, out=sys.stdout): debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 0)) - univention.debug.set_level(univention.debug.LDAP, debug_level) - univention.debug.set_level(univention.debug.ADMIN, debug_level) + ud.set_level(ud.LDAP, debug_level) + ud.set_level(ud.ADMIN, debug_level) if binddn and bindpwd: - univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using %s account" % binddn) + ud.debug(ud.ADMIN, ud.INFO, "using %s account" % binddn) try: lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, start_tls=tls, bindpw=bindpwd) except Exception, e: - univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) + ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e)) print >> out, 'authentication error: %s' % (e,) raise Failed() policyOptions.extend(['-D', binddn, '-w', bindpwd]) ## FIXME not so nice else: if os.path.exists('/etc/ldap.secret'): - univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using cn=admin,%s account" % baseDN) + ud.debug(ud.ADMIN, ud.INFO, "using cn=admin,%s account" % baseDN) secretFileName='/etc/ldap.secret' binddn='cn=admin,'+baseDN policyOptions.extend(['-D', binddn, '-y', secretFileName]) elif os.path.exists('/etc/machine.secret'): - univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using %s account" % configRegistry['ldap/hostdn']) + ud.debug(ud.ADMIN, ud.INFO, "using %s account" % configRegistry['ldap/hostdn']) secretFileName='/etc/machine.secret' binddn=configRegistry['ldap/hostdn'] policyOptions.extend(['-D', binddn, '-y', secretFileName]) @@ -614,7 +614,7 @@ def _doit(arglist, out=sys.stdout): try: lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, bindpw=pwd, start_tls=tls) except Exception, e: - univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) + ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e)) print >> out, 'authentication error: %s' % (e,) raise Failed() @@ -626,7 +626,7 @@ def _doit(arglist, out=sys.stdout): try: position=univention.admin.uldap.position(baseDN) position.setDn(position_dn) - except univention.admin.uexceptions.noObject: + except uex.noObject: print >> out, 'E: Invalid position' raise Failed() @@ -652,7 +652,7 @@ def _doit(arglist, out=sys.stdout): if superordinate_dn and univention.admin.modules.superordinate(module): try: superordinate=univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn) - except univention.admin.uexceptions.insufficientInformation, e: + except uex.insufficientInformation, e: print >> out, 'Insufficient Information: %s' % (e,) raise Failed() else: @@ -747,7 +747,7 @@ def _doit(arglist, out=sys.stdout): raise Failed() try: object=module.object(co, lo, position=position, superordinate=superordinate) - except univention.admin.uexceptions.insufficientInformation: + except uex.insufficientInformation: print >> out, 'E: Insufficient information' print >> out, 'Superordinate object is missing' raise Failed() @@ -760,11 +760,11 @@ def _doit(arglist, out=sys.stdout): print >> out, 'WARNING:%s' % object.open_warning try: object_input(module, object, input, append=append, out=out) - except univention.admin.uexceptions.nextFreeIp: + except uex.nextFreeIp: if not ignore_exists: print >> out, 'E: No free IP address found' raise Failed() - except univention.admin.uexceptions.valueInvalidSyntax, err: + except uex.valueInvalidSyntax, err: print >> out, 'E: Invalid Syntax: %s' % err raise Failed() except Exception, err: @@ -774,44 +774,44 @@ def _doit(arglist, out=sys.stdout): exists_msg=None try: dn=object.create() - except univention.admin.uexceptions.objectExists, dn: + except uex.objectExists, dn: exists_msg = dn if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except univention.admin.uexceptions.uidAlreadyUsed, user: + except uex.uidAlreadyUsed, user: exists_msg = '(uid) %s' % user if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except univention.admin.uexceptions.groupNameAlreadyUsed, group: + except uex.groupNameAlreadyUsed, group: exists_msg = '(group) %s' % group if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except univention.admin.uexceptions.dhcpServerAlreadyUsed, name: + except uex.dhcpServerAlreadyUsed, name: exists_msg = '(dhcpserver) %s' % name if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except univention.admin.uexceptions.macAlreadyUsed, mac: + except uex.macAlreadyUsed, mac: exists_msg = '(mac) %s' % mac if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except univention.admin.uexceptions.noLock, e: + except uex.noLock, e: exists_msg = '(nolock) %s' % str(e) if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except univention.admin.uexceptions.invalidDhcpEntry: + except uex.invalidDhcpEntry: print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' raise Failed() - except univention.admin.uexceptions.invalidOptions, e: + except uex.invalidOptions, e: if not ignore_exists: print >> out, 'E: invalid Options: %s' % e raise Failed() - except univention.admin.uexceptions.insufficientInformation: + except uex.insufficientInformation: print >> out, 'E: Insufficient information' print >> out, 'The following parameters are missing:' for i in module.property_descriptions: @@ -820,10 +820,10 @@ def _doit(arglist, out=sys.stdout): if i not in object or (not object[i] or (isinstance(object[i], list) and object[i]==[''])): print >> out, i raise Failed() - except univention.admin.uexceptions.noObject, e: + except uex.noObject, e: print >> out, 'E: object not found: %s' % e raise Failed() - except univention.admin.uexceptions.circularGroupDependency, e: + except uex.circularGroupDependency, e: print >> out, 'E: circular group dependency detected: %s' % e raise Failed() @@ -854,7 +854,7 @@ def _doit(arglist, out=sys.stdout): try: object=univention.admin.objects.get(module, co, lo, position='', dn=dn) - except univention.admin.uexceptions.noObject: + except uex.noObject: print >> out, 'E: object not found' raise Failed() @@ -883,19 +883,19 @@ def _doit(arglist, out=sys.stdout): try: object.move(newdn) object_modified+=1 - except univention.admin.uexceptions.noObject: + except uex.noObject: print >> out, 'E: object not found' raise Failed() - except univention.admin.uexceptions.ldapError, msg: + except uex.ldapError, msg: print >> out, "ldap Error: %s" % msg raise Failed() - except univention.admin.uexceptions.nextFreeIp: + except uex.nextFreeIp: print >> out, 'E: No free IP address found' raise Failed() - except univention.admin.uexceptions.valueInvalidSyntax, err: + except uex.valueInvalidSyntax, err: print >> out, 'E: Invalid Syntax: %s' % err raise Failed() - except univention.admin.uexceptions.invalidOperation, msg: + except uex.invalidOperation, msg: print >> out, str(msg) raise Failed() @@ -909,23 +909,23 @@ def _doit(arglist, out=sys.stdout): object.options.append(option) try: object_input(module, object, input, append, remove, out=out) - except univention.admin.uexceptions.valueMayNotChange,e: + except uex.valueMayNotChange,e: print >> out, unicode(e[0]) raise Failed() if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options: try: dn=object.modify() object_modified+=1 - except univention.admin.uexceptions.noObject: + except uex.noObject: print >> out, 'E: object not found' raise Failed() - except univention.admin.uexceptions.invalidDhcpEntry: + except uex.invalidDhcpEntry: print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' raise Failed() - except univention.admin.uexceptions.circularGroupDependency, e: + except uex.circularGroupDependency, e: print >> out, 'E: circular group dependency detected: %s' % e raise Failed() - except univention.admin.uexceptions.valueInvalidSyntax, e: + except uex.valueInvalidSyntax, e: print >> out, 'E: Invalid Syntax: %s' % e raise Failed() @@ -973,7 +973,7 @@ def _doit(arglist, out=sys.stdout): else: print >> out, 'E: dn or filter needed' raise Failed() - except (univention.admin.uexceptions.noObject, IndexError): + except (uex.noObject, IndexError): print >> out, 'E: object not found' raise Failed() @@ -987,13 +987,13 @@ def _doit(arglist, out=sys.stdout): if recursive: try: object.remove(recursive) - except univention.admin.uexceptions.ldapError,msg: + except uex.ldapError,msg: print >> out, str(msg) raise Failed() else: try: object.remove() - except univention.admin.uexceptions.primaryGroupUsed: + except uex.primaryGroupUsed: print >> out, 'E: object in use' raise Failed() print >> out, 'Object removed: %s' % _2utf8(dn) @@ -1074,10 +1074,10 @@ def _doit(arglist, out=sys.stdout): print >> out, '' print >> out, '' - except univention.admin.uexceptions.ldapError, errmsg: + except uex.ldapError, errmsg: print >> out, '%s' % (errmsg,) raise Failed() - except univention.admin.uexceptions.valueInvalidSyntax, errmsg: + except uex.valueInvalidSyntax, errmsg: print >> out, '%s' % (errmsg.message,) raise Failed() else: -- --- .../modules/univention/admincli/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -559,7 +559,7 @@ def _doit(arglist, out=sys.stdout): policy_dereference.append(val) if logfile: - ud.init(logfile, 1, 0) + ud.init(logfile, ud.FLUSH, ud.NO_FUNCTION) else: print >> out, "WARNING: no logfile specified" -- --- .../modules/univention/admincli/admin.py | 25 +++++++++------------- 1 file changed, 10 insertions(+), 15 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -34,7 +34,6 @@ from textwrap import dedent import sys import getopt import re -import string import base64 import os import subprocess @@ -672,9 +671,8 @@ def _doit(arglist, out=sys.stdout): for opt, val in opts: if opt == '--set': - pos=val.find('=') - name=val[:pos] - value = _2utf8( val[ pos + 1 : ] ) + name, value = val.split('=', 1) + value = _2utf8(value) for mod, (properties,options) in information.items(): if name in properties: @@ -688,9 +686,8 @@ def _doit(arglist, out=sys.stdout): else: print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name elif opt == '--append': - pos=val.find('=') - name=val[:pos] - value = _2utf8( val[ pos + 1 : ] ) + name, value = val.split('=', 1) + value = _2utf8(value) for mod, (properties,options) in information.items(): if name in properties: if properties[name].multivalue: @@ -704,13 +701,11 @@ def _doit(arglist, out=sys.stdout): print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name elif opt == '--remove': - pos=val.find('=') - if pos == -1: - name=val - value=None - else: - name=val[:pos] - value = _2utf8( val[ pos + 1 : ] ) + try: + name, value = val.split('=', 1) + value = _2utf8(value) + except ValueError: + name, value = val, None for mod, (properties,options) in information.items(): if name in properties: if properties[name].multivalue: @@ -878,7 +873,7 @@ def _doit(arglist, out=sys.stdout): if not res: print >> out, "position does not exsist: %s" % position_dn raise Failed() - rdn = dn[:string.find(dn,',')] + rdn, _old_base = dn.split(',', 1) newdn="%s,%s" % (rdn,position_dn) try: object.move(newdn) -- --- .../modules/univention/admincli/admin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -723,7 +723,7 @@ def _doit(arglist, out=sys.stdout): recursive = True - if action in ['modify','edit','create','new']: + if action in ('modify', 'edit', 'create', 'new'): for el in policy_reference: oc = lo.get(el, ['objectClass']) if not oc: @@ -735,7 +735,7 @@ def _doit(arglist, out=sys.stdout): #+++# ACTION CREATE #+++# - if action == 'create' or action == 'new': + if action in ('create', 'new'): if getattr(module, 'operations', None): if not 'add' in module.operations: print >> out, 'Create %s not allowed' % module_name @@ -896,7 +896,7 @@ def _doit(arglist, out=sys.stdout): else: # modify - if (len(input)+len(append)+len(remove)+len(parsed_append_options)+len(parsed_options))>0: + if any((input, append, remove, parsed_append_options, parsed_options)): if parsed_options: object.options=parsed_options if parsed_append_options: -- --- .../modules/univention/admincli/admin.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -588,19 +588,17 @@ def _doit(arglist, out=sys.stdout): policyOptions.extend(['-D', binddn, '-w', bindpwd]) ## FIXME not so nice else: - if os.path.exists('/etc/ldap.secret'): - ud.debug(ud.ADMIN, ud.INFO, "using cn=admin,%s account" % baseDN) - secretFileName='/etc/ldap.secret' - binddn='cn=admin,'+baseDN - policyOptions.extend(['-D', binddn, '-y', secretFileName]) - elif os.path.exists('/etc/machine.secret'): - ud.debug(ud.ADMIN, ud.INFO, "using %s account" % configRegistry['ldap/hostdn']) - secretFileName='/etc/machine.secret' - binddn=configRegistry['ldap/hostdn'] - policyOptions.extend(['-D', binddn, '-y', secretFileName]) + for binddn, secretFileName in ( + ('cn=admin,' + baseDN, '/etc/ldap.secret'), + (configRegistry['ldap/hostdn'], '/etc/machine.secret'), + ): + if os.path.exists(secretFileName): + break else: print >> out, "E: Missing LDAP credentials" raise Failed() + ud.debug(ud.ADMIN, ud.INFO, "using %s account" % binddn) + policyOptions.extend(['-D', binddn, '-y', secretFileName]) try: secretFile=open(secretFileName,'r') -- --- .../modules/univention/admincli/admin.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -484,7 +484,7 @@ def _doit(arglist, out=sys.stdout): 'policy-reference=', 'policy-dereference=', 'remove_referring', - 'recursive' + 'recursive', ] try: opts, args=getopt.getopt(arglist[3:], '', longopts) @@ -580,7 +580,14 @@ def _doit(arglist, out=sys.stdout): if binddn and bindpwd: ud.debug(ud.ADMIN, ud.INFO, "using %s account" % binddn) try: - lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, start_tls=tls, bindpw=bindpwd) + lo = univention.admin.uldap.access( + host=configRegistry['ldap/master'], + port=int(configRegistry.get('ldap/master/port', 7389)), + base=baseDN, + binddn=binddn, + start_tls=tls, + bindpw=bindpwd + ) except Exception, e: ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e)) print >> out, 'authentication error: %s' % (e,) @@ -863,11 +870,10 @@ def _doit(arglist, out=sys.stdout): if not position_dn: print >> out, "need new position for moving object" else: - res = '' try: # check if global-position exists res = lo.get(position_dn) except: - pass + res = '' if not res: print >> out, "position does not exsist: %s" % position_dn raise Failed() -- --- .../modules/univention/admincli/admin.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -160,7 +160,7 @@ def _print_property(module, action, name, out=sys.stdout): required[ 'editable' ] = False flags = '' - if action in required and required[ action ]: + if required.get(action): flags='*' elif not action in required: if required[ 'create' ]: @@ -171,16 +171,13 @@ def _print_property(module, action, name, out=sys.stdout): flags += 'r' if not required[ 'editable' ]: flags += 'e' + flags = [flags] if flags else [] if property.options: - if flags: - flags += ',' - flags += ','.join(property.options) + flags.extend(property.options) if property.multivalue: - if flags: - flags += ',' - flags += '[]' + flags.append('[]') if flags: - name += ' (%s)' % (flags,) + name += ' (%s)' % (','.join(flags),) print >> out, ' %-40s %s' % ( name, -- --- .../modules/univention/admincli/admin.py | 533 +++++++++++---------- .../univention-cli-server | 8 +- 2 files changed, 275 insertions(+), 266 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -49,6 +49,7 @@ from univention.admin.layout import Group from univention.config_registry import ConfigRegistry import univention.admin.ipaddress + univention.admin.modules.update() # update choices-lists which are defined in LDAP @@ -134,7 +135,7 @@ def version(out=sys.stdout): def _print_property(module, action, name, out=sys.stdout): - property = module.property_descriptions.get( name ) + property = module.property_descriptions.get(name) if property is None: print >> out, 'E: unknown property %s of module %s' % ( name, @@ -143,33 +144,33 @@ def _print_property(module, action, name, out=sys.stdout): return required = { - 'create' : False, - 'modify' : False, - 'remove' : False, + 'create': False, + 'modify': False, + 'remove': False, 'editable': True, - } + } if property.required: - required [ 'create' ] = True + required['create'] = True if property.identifies: - required[ 'modify' ] = True - required[ 'remove' ] = True + required['modify'] = True + required['remove'] = True if not property.editable: - required[ 'modify' ] = False - required[ 'remove' ] = False - required[ 'editable' ] = False + required['modify'] = False + required['remove'] = False + required['editable'] = False flags = '' if required.get(action): - flags='*' + flags = '*' elif not action in required: - if required[ 'create' ]: + if required['create']: flags += 'c' - if required[ 'modify' ]: + if required['modify']: flags += 'm' - if required[ 'remove' ]: + if required['remove']: flags += 'r' - if not required[ 'editable' ]: + if not required['editable']: flags += 'e' flags = [flags] if flags else [] if property.options: @@ -198,48 +199,52 @@ def module_usage(information, action='', out=sys.stdout): print >> out, '' print >> out, '%s variables:' % module.module - if not hasattr(module,"layout"): + if not hasattr(module, "layout"): continue for moduletab in module.layout: print >> out, ' %s:' % (moduletab.label) for row in moduletab.layout: - if isinstance( row, Group ): + if isinstance(row, Group): print >> out, ' %s' % row.label for row in row.layout: - if isinstance( row, basestring ): - _print_property( module, action, row, out ) + if isinstance(row, basestring): + _print_property(module, action, row, out) continue for item in row: - _print_property( module, action, item, out ) + _print_property(module, action, item, out) else: - if isinstance( row, basestring ): - _print_property( module, action, row, out ) + if isinstance(row, basestring): + _print_property(module, action, row, out) continue for item in row: - _print_property( module, action, item, out ) + _print_property(module, action, item, out) def module_information(module, identifies_only=False): - information={module:[{},{}]} + information = { + module: [{}, {}], + } if getattr(module, 'superordinate', None): - superordinate=univention.admin.modules.get(module.superordinate) + superordinate = univention.admin.modules.get(module.superordinate) information.update(module_information(superordinate, identifies_only=True)) if not identifies_only: for name, property in module.property_descriptions.items(): - information[module][0][name]=property - if hasattr(module,'options'): + information[module][0][name] = property + if hasattr(module, 'options'): for name, option in module.options.items(): - information[module][1][name]=option + information[module][1][name] = option return information -def _2utf8( text ): + +def _2utf8(text): try: - return text.encode( 'utf-8' ) + return text.encode('utf-8') except UnicodeError: - return text.decode( 'iso-8859-1' ) + return text.decode('iso-8859-1') + def object_input(module, object, input, append=None, remove=None, out=sys.stdout): if append: @@ -251,13 +256,13 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout else: print >> out, 'WARNING: file not found: %s' % value - elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): + elif univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex): for i in value: test_val = i.split('"') if test_val[0] and test_val[0] == i: val = i.split(' ') else: - val=[] + val = [] for j in test_val: j = j.strip() if j: @@ -286,14 +291,14 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout print >> out, 'E: Invalid Syntax: %s' % (errmsg,) if remove: for key, value in remove.items(): - if univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): + if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex): if value: for i in value: test_val = i.split('"') if test_val[0] and test_val[0] == i: val = i.split(' ') else: - val=[] + val = [] print >> out, 'test_val=%s' % (test_val,) for j in test_val: j = j.strip() @@ -307,14 +312,14 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout else: print >> out, "WARNING: cannot remove %s from %s, value does not exist" % (val, key) else: - object[key]=[] + object[key] = [] else: if isinstance(object[key], basestring): - object[key] = [ object[key] ] + object[key] = [object[key]] vallist = value if isinstance(value, basestring): - vallist = [ value ] + vallist = [value] for val in vallist: if val in object[key]: @@ -325,45 +330,45 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout for key, value in input.items(): if module.property_descriptions[key].syntax.name == 'binaryfile': if value == '': - object[key]=value + object[key] = value elif os.path.exists(value): fh = open(value, 'r') - content=fh.read() + content = fh.read() if "----BEGIN CERTIFICATE-----" in content: - content = content.replace('----BEGIN CERTIFICATE-----','') - content = content.replace('----END CERTIFICATE-----','') - object[key]=base64.decodestring(content) + content = content.replace('----BEGIN CERTIFICATE-----', '') + content = content.replace('----END CERTIFICATE-----', '') + object[key] = base64.decodestring(content) else: - object[key]= content + object[key] = content fh.close() else: print >> out, 'WARNING: file not found: %s' % value - elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): + elif univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex): if isinstance(value, list): for i in value: test_val = i.split('"') if test_val[0] and test_val[0] == value[i]: - val=value[i].split(' ') + val = value[i].split(' ') else: - val=[] + val = [] for j in test_val: j = j.strip() if j: val.append(j) else: - val=value.split(' ') + val = value.split(' ') if module.property_descriptions[key].multivalue: - object[key]=[val] + object[key] = [val] else: - object[key]=val + object[key] = val else: try: - object[key]=value + object[key] = value except uex.ipOverridesNetwork, e: print >> out, 'WARNING: %s' % e.message except uex.valueMayNotChange, e: - raise uex.valueMayNotChange, "%s: %s"%(e.message, key) + raise uex.valueMayNotChange, "%s: %s" % (e.message, key) def list_available_modules(out=sys.stdout): @@ -453,8 +458,7 @@ def _doit(arglist, out=sys.stdout): usage(out=out) raise Failed() - module_name=arglist[1] - + module_name = arglist[1] if module_name == 'modules': return list_available_modules(out=out) @@ -484,7 +488,7 @@ def _doit(arglist, out=sys.stdout): 'recursive', ] try: - opts, args=getopt.getopt(arglist[3:], '', longopts) + opts, args = getopt.getopt(arglist[3:], '', longopts) except getopt.error, msg: print >> out, msg raise Failed() @@ -494,61 +498,61 @@ def _doit(arglist, out=sys.stdout): " ".join(('"%s"' % _ for _ in args)), ) - position_dn='' - dn='' - binddn=None - bindpwd=None - list_policies=False - policies_with_DN=False - policyOptions=[] - logfile='/var/log/univention/directory-manager-cmd.log' - tls=2 + position_dn = '' + dn = '' + binddn = None + bindpwd = None + list_policies = False + policies_with_DN = False + policyOptions = [] + logfile = '/var/log/univention/directory-manager-cmd.log' + tls = 2 ignore_exists = False - superordinate_dn='' - parsed_append_options=[] - parsed_options=[] - filter='' - input={} - append={} - remove={} - policy_reference=[] - policy_dereference=[] + superordinate_dn = '' + parsed_append_options = [] + parsed_options = [] + filter = '' + input = {} + append = {} + remove = {} + policy_reference = [] + policy_dereference = [] for opt, val in opts: if opt == '--position': - position_dn = _2utf8( val ) + position_dn = _2utf8(val) elif opt == '--logfile': - logfile=val + logfile = val elif opt == '--policies': list_policies = True - if val=="1": + if val == "1": policies_with_DN = True else: policyOptions = ['-s'] elif opt == '--binddn': - binddn=val + binddn = val elif opt == '--bindpwd': - bindpwd=val + bindpwd = val elif opt == '--bindpwdfile': try: with open(val) as fp: - bindpwd=fp.read().strip() + bindpwd = fp.read().strip() except IOError as e: print >> out, 'E: could not read bindpwd from file (%s)' % (e,) raise Failed() elif opt == '--dn': - dn = _2utf8( val ) + dn = _2utf8(val) elif opt == '--tls': - tls=val + tls = val elif opt == '--ignore_exists': ignore_exists = True elif opt == '--superordinate': - superordinate_dn=val + superordinate_dn = val elif opt == '--option': parsed_options.append(val) elif opt == '--append-option': parsed_append_options.append(val) elif opt == '--filter': - filter=val + filter = val elif opt == '--policy-reference': policy_reference.append(val) elif opt == '--policy-dereference': @@ -563,11 +567,11 @@ def _doit(arglist, out=sys.stdout): configRegistry.load() if configRegistry.get('ldap/master'): - co=univention.admin.config.config(configRegistry['ldap/master']) + co = univention.admin.config.config(configRegistry['ldap/master']) else: - co=univention.admin.config.config() + co = univention.admin.config.config() - baseDN=configRegistry['ldap/base'] + baseDN = configRegistry['ldap/base'] debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 0)) @@ -589,7 +593,7 @@ def _doit(arglist, out=sys.stdout): ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e)) print >> out, 'authentication error: %s' % (e,) raise Failed() - policyOptions.extend(['-D', binddn, '-w', bindpwd]) ## FIXME not so nice + policyOptions.extend(['-D', binddn, '-w', bindpwd]) # FIXME not so nice else: for binddn, secretFileName in ( @@ -605,34 +609,41 @@ def _doit(arglist, out=sys.stdout): policyOptions.extend(['-D', binddn, '-y', secretFileName]) try: - secretFile=open(secretFileName,'r') + secretFile = open(secretFileName, 'r') except IOError: print >> out, 'E: Permission denied, try --binddn and --bindpwd' raise Failed() - pwdLine=secretFile.readline() - pwd=re.sub('\n','',pwdLine) + pwdLine = secretFile.readline() + pwd = re.sub('\n', '', pwdLine) try: - lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, bindpw=pwd, start_tls=tls) + lo = univention.admin.uldap.access( + host=configRegistry['ldap/master'], + port=int(configRegistry.get('ldap/master/port', '7389')), + base=baseDN, + binddn=binddn, + bindpw=pwd, + start_tls=tls + ) except Exception, e: ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e)) print >> out, 'authentication error: %s' % (e,) raise Failed() if not position_dn and superordinate_dn: - position_dn=superordinate_dn + position_dn = superordinate_dn elif not position_dn: - position_dn=baseDN + position_dn = baseDN try: - position=univention.admin.uldap.position(baseDN) + position = univention.admin.uldap.position(baseDN) position.setDn(position_dn) except uex.noObject: print >> out, 'E: Invalid position' raise Failed() try: - module=univention.admin.modules.get(module_name) + module = univention.admin.modules.get(module_name) except: print >> out, "failed to get module %s." % module_name print >> out, "" @@ -646,58 +657,56 @@ def _doit(arglist, out=sys.stdout): raise Failed() # initialise modules - univention.admin.modules.init(lo,position,module) + univention.admin.modules.init(lo, position, module) - information=module_information(module) + information = module_information(module) if superordinate_dn and univention.admin.modules.superordinate(module): try: - superordinate=univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn) + superordinate = univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn) except uex.insufficientInformation, e: print >> out, 'Insufficient Information: %s' % (e,) raise Failed() else: - superordinate=None - + superordinate = None if len(arglist) == 2: module_usage(information, out=out) raise Failed() - action=arglist[2] + action = arglist[2] if len(arglist) == 3 and action != 'list': module_usage(information, action, out=out) raise Failed() - for opt, val in opts: if opt == '--set': name, value = val.split('=', 1) value = _2utf8(value) - - for mod, (properties,options) in information.items(): + for mod, (properties, options) in information.items(): if name in properties: if properties[name].multivalue: values = input.setdefault(name, []) if value: values.append(value) else: - input[name]=value + input[name] = value break else: print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name + elif opt == '--append': name, value = val.split('=', 1) value = _2utf8(value) - for mod, (properties,options) in information.items(): + for mod, (properties, options) in information.items(): if name in properties: if properties[name].multivalue: values = append.setdefault(name, []) if value: values.append(value) else: - append[name]=value + append[name] = value break else: print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name @@ -708,135 +717,135 @@ def _doit(arglist, out=sys.stdout): value = _2utf8(value) except ValueError: name, value = val, None - for mod, (properties,options) in information.items(): + for mod, (properties, options) in information.items(): if name in properties: if properties[name].multivalue: values = remove.setdefault(name, []) if value: values.append(value) else: - remove[name]=value + remove[name] = value break else: print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name + elif opt == '--remove_referring': remove_referring = True + elif opt == '--recursive': recursive = True - if action in ('modify', 'edit', 'create', 'new'): - for el in policy_reference: - oc = lo.get(el, ['objectClass']) - if not oc: - print >> out, "Object to be referenced does not exist: %s" % (el,) - raise Failed() - if not 'univentionPolicy' in oc['objectClass']: - print >> out, "Object to be referenced is no valid Policy: %s" % (el,) - raise Failed() - + for el in policy_reference: + oc = lo.get(el, ['objectClass']) + if not oc: + print >> out, "Object to be referenced does not exist: %s" % (el,) + raise Failed() + if not 'univentionPolicy' in oc['objectClass']: + print >> out, "Object to be referenced is no valid Policy: %s" % (el,) + raise Failed() -#+++# ACTION CREATE #+++# + #+++# ACTION CREATE #+++# if action in ('create', 'new'): - if getattr(module, 'operations', None): - if not 'add' in module.operations: - print >> out, 'Create %s not allowed' % module_name - raise Failed() - try: - object=module.object(co, lo, position=position, superordinate=superordinate) - except uex.insufficientInformation: - print >> out, 'E: Insufficient information' - print >> out, 'Superordinate object is missing' + if getattr(module, 'operations', None): + if not 'add' in module.operations: + print >> out, 'Create %s not allowed' % module_name raise Failed() + try: + object = module.object(co, lo, position=position, superordinate=superordinate) + except uex.insufficientInformation: + print >> out, 'E: Insufficient information' + print >> out, 'Superordinate object is missing' + raise Failed() - if parsed_options: - object.options=parsed_options + if parsed_options: + object.options = parsed_options - object.open() - if getattr(object, 'open_warning', None): - print >> out, 'WARNING:%s' % object.open_warning - try: - object_input(module, object, input, append=append, out=out) - except uex.nextFreeIp: - if not ignore_exists: - print >> out, 'E: No free IP address found' - raise Failed() - except uex.valueInvalidSyntax, err: - print >> out, 'E: Invalid Syntax: %s' % err - raise Failed() - except Exception, err: - print >> out, 'E: Option %s is not valid' % err + object.open() + if getattr(object, 'open_warning', None): + print >> out, 'WARNING:%s' % object.open_warning + try: + object_input(module, object, input, append=append, out=out) + except uex.nextFreeIp: + if not ignore_exists: + print >> out, 'E: No free IP address found' raise Failed() + except uex.valueInvalidSyntax, err: + print >> out, 'E: Invalid Syntax: %s' % err + raise Failed() + except Exception, err: + print >> out, 'E: Option %s is not valid' % err + raise Failed() - exists_msg=None - try: - dn=object.create() - except uex.objectExists, dn: - exists_msg = dn - if not ignore_exists: - print >> out, 'E: Object exists: %s' % exists_msg - raise Failed() - except uex.uidAlreadyUsed, user: - exists_msg = '(uid) %s' % user - if not ignore_exists: - print >> out, 'E: Object exists: %s' % exists_msg - raise Failed() - except uex.groupNameAlreadyUsed, group: - exists_msg = '(group) %s' % group - if not ignore_exists: - print >> out, 'E: Object exists: %s' % exists_msg - raise Failed() - except uex.dhcpServerAlreadyUsed, name: - exists_msg = '(dhcpserver) %s' % name - if not ignore_exists: - print >> out, 'E: Object exists: %s' % exists_msg - raise Failed() - except uex.macAlreadyUsed, mac: - exists_msg = '(mac) %s' % mac - if not ignore_exists: - print >> out, 'E: Object exists: %s' % exists_msg - raise Failed() - except uex.noLock, e: - exists_msg = '(nolock) %s' % str(e) - if not ignore_exists: - print >> out, 'E: Object exists: %s' % exists_msg - raise Failed() - except uex.invalidDhcpEntry: - print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' + exists_msg = None + try: + dn = object.create() + except uex.objectExists, dn: + exists_msg = dn + if not ignore_exists: + print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except uex.invalidOptions, e: - if not ignore_exists: - print >> out, 'E: invalid Options: %s' % e - raise Failed() - except uex.insufficientInformation: - print >> out, 'E: Insufficient information' - print >> out, 'The following parameters are missing:' - for i in module.property_descriptions: - property=module.property_descriptions.get(i) - if property.required: - if i not in object or (not object[i] or (isinstance(object[i], list) and object[i]==[''])): - print >> out, i + except uex.uidAlreadyUsed, user: + exists_msg = '(uid) %s' % user + if not ignore_exists: + print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except uex.noObject, e: - print >> out, 'E: object not found: %s' % e + except uex.groupNameAlreadyUsed, group: + exists_msg = '(group) %s' % group + if not ignore_exists: + print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except uex.circularGroupDependency, e: - print >> out, 'E: circular group dependency detected: %s' % e + except uex.dhcpServerAlreadyUsed, name: + exists_msg = '(dhcpserver) %s' % name + if not ignore_exists: + print >> out, 'E: Object exists: %s' % exists_msg raise Failed() + except uex.macAlreadyUsed, mac: + exists_msg = '(mac) %s' % mac + if not ignore_exists: + print >> out, 'E: Object exists: %s' % exists_msg + raise Failed() + except uex.noLock, e: + exists_msg = '(nolock) %s' % str(e) + if not ignore_exists: + print >> out, 'E: Object exists: %s' % exists_msg + raise Failed() + except uex.invalidDhcpEntry: + print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' + raise Failed() + except uex.invalidOptions, e: + if not ignore_exists: + print >> out, 'E: invalid Options: %s' % e + raise Failed() + except uex.insufficientInformation: + print >> out, 'E: Insufficient information' + print >> out, 'The following parameters are missing:' + for i in module.property_descriptions: + property = module.property_descriptions.get(i) + if property.required: + if i not in object or (not object[i] or (isinstance(object[i], list) and object[i] == [''])): + print >> out, i + raise Failed() + except uex.noObject, e: + print >> out, 'E: object not found: %s' % e + raise Failed() + except uex.circularGroupDependency, e: + print >> out, 'E: circular group dependency detected: %s' % e + raise Failed() - if policy_reference: - lo.modify(dn,[('objectClass','','univentionPolicyReference')]) - modlist = [('univentionPolicyReference', '', el) for el in policy_reference] - lo.modify(dn,modlist) + if policy_reference: + lo.modify(dn, [('objectClass', '', 'univentionPolicyReference')]) + modlist = [('univentionPolicyReference', '', el) for el in policy_reference] + lo.modify(dn, modlist) - if exists_msg: - print >> out, 'Object exists: %s' % exists_msg - else: - if not dn: - dn=object.dn - print >> out, 'Object created: %s' % _2utf8(dn) + if exists_msg: + print >> out, 'Object exists: %s' % exists_msg + else: + if not dn: + dn = object.dn + print >> out, 'Object created: %s' % _2utf8(dn) -#+++# ACTION MODIFY #+++# + #+++# ACTION MODIFY #+++# elif action == 'modify' or action == 'edit' or action == 'move': if not dn: print >> out, 'E: DN is missing' @@ -850,7 +859,7 @@ def _doit(arglist, out=sys.stdout): raise Failed() try: - object=univention.admin.objects.get(module, co, lo, position='', dn=dn) + object = univention.admin.objects.get(module, co, lo, position='', dn=dn) except uex.noObject: print >> out, 'E: object not found' raise Failed() @@ -875,10 +884,10 @@ def _doit(arglist, out=sys.stdout): print >> out, "position does not exsist: %s" % position_dn raise Failed() rdn, _old_base = dn.split(',', 1) - newdn="%s,%s" % (rdn,position_dn) + newdn = "%s,%s" % (rdn, position_dn) try: object.move(newdn) - object_modified+=1 + object_modified += 1 except uex.noObject: print >> out, 'E: object not found' raise Failed() @@ -895,23 +904,22 @@ def _doit(arglist, out=sys.stdout): print >> out, str(msg) raise Failed() - else: # modify - + else: # modify if any((input, append, remove, parsed_append_options, parsed_options)): if parsed_options: - object.options=parsed_options + object.options = parsed_options if parsed_append_options: for option in parsed_append_options: object.options.append(option) try: object_input(module, object, input, append, remove, out=out) - except uex.valueMayNotChange,e: + except uex.valueMayNotChange, e: print >> out, unicode(e[0]) raise Failed() if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options: try: - dn=object.modify() - object_modified+=1 + dn = object.modify() + object_modified += 1 except uex.noObject: print >> out, 'E: object not found' raise Failed() @@ -926,10 +934,10 @@ def _doit(arglist, out=sys.stdout): raise Failed() if policy_reference: - if 'univentionPolicyReference' not in lo.get(dn,['objectClass'])['objectClass']: - lo.modify(dn,[('objectClass','','univentionPolicyReference')]) - object_modified+=1 - modlist=[] + if 'univentionPolicyReference' not in lo.get(dn, ['objectClass'])['objectClass']: + lo.modify(dn, [('objectClass', '', 'univentionPolicyReference')]) + object_modified += 1 + modlist = [] upr = lo.search(base=dn, scope='base', attr=['univentionPolicyReference'])[0][1] if 'univentionPolicyReference' not in upr: upr['univentionPolicyReference'] = [] @@ -937,15 +945,15 @@ def _doit(arglist, out=sys.stdout): if val in upr['univentionPolicyReference']: print >> out, 'WARNING: cannot append %s to univentionPolicyReference, value exists' % val else: - modlist.append(('univentionPolicyReference','',el)) + modlist.append(('univentionPolicyReference', '', el)) if modlist: - lo.modify(dn,modlist) - object_modified+=1 + lo.modify(dn, modlist) + object_modified += 1 if policy_dereference: modlist = [('univentionPolicyReference', el, '') for el in policy_dereference] - lo.modify(dn,modlist) - object_modified+=1 + lo.modify(dn, modlist) + object_modified += 1 if object_modified > 0: print >> out, 'Object modified: %s' % _2utf8(dn) @@ -953,7 +961,6 @@ def _doit(arglist, out=sys.stdout): print >> out, 'No modification: %s' % _2utf8(dn) elif action == 'remove' or action == 'delete': - if getattr(module, 'operations', None): if not 'remove' in module.operations: print >> out, 'Remove %s not allowed' % module_name @@ -961,11 +968,11 @@ def _doit(arglist, out=sys.stdout): try: if dn and filter: - object=univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=dn, filter=filter, required=1, unique=1)[0] + object = univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=dn, filter=filter, required=1, unique=1)[0] elif dn: - object=univention.admin.modules.lookup(module, co, lo, scope='base', superordinate=superordinate, base=dn, filter=filter, required=1, unique=1)[0] + object = univention.admin.modules.lookup(module, co, lo, scope='base', superordinate=superordinate, base=dn, filter=filter, required=1, unique=1)[0] elif filter: - object=univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter, required=1, unique=1)[0] + object = univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter, required=1, unique=1)[0] else: print >> out, 'E: dn or filter needed' raise Failed() @@ -983,7 +990,7 @@ def _doit(arglist, out=sys.stdout): if recursive: try: object.remove(recursive) - except uex.ldapError,msg: + except uex.ldapError, msg: print >> out, str(msg) raise Failed() else: @@ -995,7 +1002,6 @@ def _doit(arglist, out=sys.stdout): print >> out, 'Object removed: %s' % _2utf8(dn) elif action == 'list' or action == 'lookup': - if getattr(module, 'operations', None): if not 'search' in module.operations: print >> out, 'Search %s not allowed' % module_name @@ -1012,7 +1018,7 @@ def _doit(arglist, out=sys.stdout): if getattr(object, 'open_warning', None): print >> out, 'WARNING: %s' % object.open_warning for key, value in object.items(): - s=module.property_descriptions[key].syntax + s = module.property_descriptions[key].syntax if module.property_descriptions[key].multivalue: for v in value: if s.tostring(v): @@ -1025,9 +1031,11 @@ def _doit(arglist, out=sys.stdout): else: print >> out, ' %s: %s' % (_2utf8(key), None) - if 'univentionPolicyReference' in lo.get(univention.admin.objects.dn(object),['objectClass'])['objectClass']: - references = lo.get( _2utf8(univention.admin.objects.dn( object ) ), - [ 'univentionPolicyReference' ] ) + if 'univentionPolicyReference' in lo.get(univention.admin.objects.dn(object), ['objectClass'])['objectClass']: + references = lo.get( + _2utf8(univention.admin.objects.dn(object)), + ['univentionPolicyReference'] + ) if references: for el in references['univentionPolicyReference']: print >> out, ' %s: %s' % ( @@ -1036,38 +1044,37 @@ def _doit(arglist, out=sys.stdout): ) if list_policies: - utf8_objectdn = _2utf8( univention.admin.objects.dn( object ) ) + utf8_objectdn = _2utf8(univention.admin.objects.dn(object)) print >> out, " Policy-based Settings:" client = get_policy(utf8_objectdn, out, policyOptions, policies_with_DN) print >> out, '' if module_name == 'dhcp/host': - subnet_module=univention.admin.modules.get('dhcp/subnet') - for subnet in univention.admin.modules.lookup(subnet_module, co, lo, scope='sub', superordinate=superordinate, base='', filter=''): - - if univention.admin.ipaddress.ip_is_in_network(subnet['subnet'], subnet['subnetmask'], object['fixedaddress'][0]): - utf8_subnet_dn = _2utf8( subnet.dn ) - print >> out, " Subnet-based Settings:" - ddict = get_policy(utf8_subnet_dn, out, policyOptions, policies_with_DN) - print >> out, '' - - print >> out, " Merged Settings:" - - for key, values in ddict.items(): - if key not in client: - client[key] = values - - if policies_with_DN: - for key, (policy, values) in client.items(): - print >> out, " Policy: " + policy - print >> out, " Attribute: " + key - for value in values: - print >> out, " Value: " + value - else: - for key, values in client.items(): - for value in values: - print >> out, " %s=%s" % (key, value) - print >> out, '' + subnet_module = univention.admin.modules.get('dhcp/subnet') + for subnet in univention.admin.modules.lookup(subnet_module, co, lo, scope='sub', superordinate=superordinate, base='', filter=''): + if univention.admin.ipaddress.ip_is_in_network(subnet['subnet'], subnet['subnetmask'], object['fixedaddress'][0]): + utf8_subnet_dn = _2utf8(subnet.dn) + print >> out, " Subnet-based Settings:" + ddict = get_policy(utf8_subnet_dn, out, policyOptions, policies_with_DN) + print >> out, '' + + print >> out, " Merged Settings:" + + for key, values in ddict.items(): + if key not in client: + client[key] = values + + if policies_with_DN: + for key, (policy, values) in client.items(): + print >> out, " Policy: " + policy + print >> out, " Attribute: " + key + for value in values: + print >> out, " Value: " + value + else: + for key, values in client.items(): + for value in values: + print >> out, " %s=%s" % (key, value) + print >> out, '' print >> out, '' except uex.ldapError, errmsg: --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server @@ -55,6 +55,7 @@ except ImportError: logfile = '' + class MyRequestHandler(SocketServer.BaseRequestHandler): """Handle request on listeneing socket to open new connection.""" def handle(self): @@ -74,10 +75,11 @@ class ForkingTCPServer(SocketServer.ForkingTCPServer): """UDM server listening on UNIX socket.""" address_family = socket.AF_UNIX allow_reuse_address = 1 + def server_bind(self): SocketServer.TCPServer.server_bind(self) _host, port = self.socket.getsockname()[:2] - self.server_name = 'localhost' #socket.getfqdn(host) + self.server_name = 'localhost' # socket.getfqdn(host) self.server_port = port @@ -104,7 +106,7 @@ def server_main(): os.kill(pid, signal.SIGCONT) except (ValueError, OSError): pid = 0 - if not pid: # no pid found or no server running + if not pid: # no pid found or no server running os.unlink(socket_path) os.unlink(runfilename) os.rmdir(socket_dir) @@ -160,7 +162,6 @@ def server_main(): if not rlist: ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] stopped after %s seconds idle' % (os.getpid(), timeout)) sys.exit(0) - finally: os.unlink(socket_path) os.unlink(runfilename) @@ -259,5 +260,6 @@ def main(): else: # parent os.waitpid(pid, os.P_NOWAIT) + if __name__ == "__main__": main() -- --- .../modules/univention/admincli/admin.py | 108 ++++++++++----------- 1 file changed, 54 insertions(+), 54 deletions(-) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -287,8 +287,8 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout tmp = list(values) tmp.append(val) object[key] = list(tmp) - except uex.valueInvalidSyntax, errmsg: - print >> out, 'E: Invalid Syntax: %s' % (errmsg,) + except uex.valueInvalidSyntax, ex: + print >> out, 'E: Invalid Syntax: %s' % (ex,) if remove: for key, value in remove.items(): if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex): @@ -365,10 +365,10 @@ def object_input(module, object, input, append=None, remove=None, out=sys.stdout else: try: object[key] = value - except uex.ipOverridesNetwork, e: - print >> out, 'WARNING: %s' % e.message - except uex.valueMayNotChange, e: - raise uex.valueMayNotChange, "%s: %s" % (e.message, key) + except uex.ipOverridesNetwork, ex: + print >> out, 'WARNING: %s' % ex.message + except uex.valueMayNotChange, ex: + raise uex.valueMayNotChange, "%s: %s" % (ex.message, key) def list_available_modules(out=sys.stdout): @@ -382,17 +382,17 @@ def list_available_modules(out=sys.stdout): def doit(arglist, out=sys.stdout): try: _doit(arglist, out) - except uex.base, e: + except uex.base, ex: ud.debug(ud.ADMIN, ud.WARN, traceback.format_exc()) # collect error information msg = [] - if getattr(e, 'message', None): - msg.append(e.message) - if getattr(e, 'args', None): + if getattr(ex, 'message', None): + msg.append(ex.message) + if getattr(ex, 'args', None): #avoid duplicate messages - if not len(msg) or len(e.args) > 1 or e.args[0] != msg[0]: - msg.extend(e.args) + if not len(msg) or len(ex.args) > 1 or ex.args[0] != msg[0]: + msg.extend(ex.args) # strip elements and make sure that a ':' is printed iff further information follows msg = [_.strip() for _ in msg] @@ -489,8 +489,8 @@ def _doit(arglist, out=sys.stdout): ] try: opts, args = getopt.getopt(arglist[3:], '', longopts) - except getopt.error, msg: - print >> out, msg + except getopt.error, ex: + print >> out, ex raise Failed() if args and isinstance(args, list): @@ -536,8 +536,8 @@ def _doit(arglist, out=sys.stdout): try: with open(val) as fp: bindpwd = fp.read().strip() - except IOError as e: - print >> out, 'E: could not read bindpwd from file (%s)' % (e,) + except IOError as ex: + print >> out, 'E: could not read bindpwd from file (%s)' % (ex,) raise Failed() elif opt == '--dn': dn = _2utf8(val) @@ -589,9 +589,9 @@ def _doit(arglist, out=sys.stdout): start_tls=tls, bindpw=bindpwd ) - except Exception, e: - ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e)) - print >> out, 'authentication error: %s' % (e,) + except Exception, ex: + ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % (ex,)) + print >> out, 'authentication error: %s' % (ex,) raise Failed() policyOptions.extend(['-D', binddn, '-w', bindpwd]) # FIXME not so nice @@ -625,9 +625,9 @@ def _doit(arglist, out=sys.stdout): bindpw=pwd, start_tls=tls ) - except Exception, e: - ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e)) - print >> out, 'authentication error: %s' % (e,) + except Exception, ex: + ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % (ex,)) + print >> out, 'authentication error: %s' % (ex,) raise Failed() if not position_dn and superordinate_dn: @@ -664,8 +664,8 @@ def _doit(arglist, out=sys.stdout): if superordinate_dn and univention.admin.modules.superordinate(module): try: superordinate = univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn) - except uex.insufficientInformation, e: - print >> out, 'Insufficient Information: %s' % (e,) + except uex.insufficientInformation, ex: + print >> out, 'Insufficient Information: %s' % (ex,) raise Failed() else: superordinate = None @@ -770,11 +770,11 @@ def _doit(arglist, out=sys.stdout): if not ignore_exists: print >> out, 'E: No free IP address found' raise Failed() - except uex.valueInvalidSyntax, err: - print >> out, 'E: Invalid Syntax: %s' % err + except uex.valueInvalidSyntax, ex: + print >> out, 'E: Invalid Syntax: %s' % ex raise Failed() - except Exception, err: - print >> out, 'E: Option %s is not valid' % err + except Exception, ex: + print >> out, 'E: Option %s is not valid' % ex raise Failed() exists_msg = None @@ -805,17 +805,17 @@ def _doit(arglist, out=sys.stdout): if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() - except uex.noLock, e: - exists_msg = '(nolock) %s' % str(e) + except uex.noLock, ex: + exists_msg = '(nolock) %s' % (ex,) if not ignore_exists: print >> out, 'E: Object exists: %s' % exists_msg raise Failed() except uex.invalidDhcpEntry: print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' raise Failed() - except uex.invalidOptions, e: + except uex.invalidOptions, ex: if not ignore_exists: - print >> out, 'E: invalid Options: %s' % e + print >> out, 'E: invalid Options: %s' % ex raise Failed() except uex.insufficientInformation: print >> out, 'E: Insufficient information' @@ -826,11 +826,11 @@ def _doit(arglist, out=sys.stdout): if i not in object or (not object[i] or (isinstance(object[i], list) and object[i] == [''])): print >> out, i raise Failed() - except uex.noObject, e: - print >> out, 'E: object not found: %s' % e + except uex.noObject, ex: + print >> out, 'E: object not found: %s' % ex raise Failed() - except uex.circularGroupDependency, e: - print >> out, 'E: circular group dependency detected: %s' % e + except uex.circularGroupDependency, ex: + print >> out, 'E: circular group dependency detected: %s' % ex raise Failed() if policy_reference: @@ -891,17 +891,17 @@ def _doit(arglist, out=sys.stdout): except uex.noObject: print >> out, 'E: object not found' raise Failed() - except uex.ldapError, msg: - print >> out, "ldap Error: %s" % msg + except uex.ldapError, ex: + print >> out, "ldap Error: %s" % ex raise Failed() except uex.nextFreeIp: print >> out, 'E: No free IP address found' raise Failed() - except uex.valueInvalidSyntax, err: - print >> out, 'E: Invalid Syntax: %s' % err + except uex.valueInvalidSyntax, ex: + print >> out, 'E: Invalid Syntax: %s' % ex raise Failed() - except uex.invalidOperation, msg: - print >> out, str(msg) + except uex.invalidOperation, ex: + print >> out, ex raise Failed() else: # modify @@ -913,8 +913,8 @@ def _doit(arglist, out=sys.stdout): object.options.append(option) try: object_input(module, object, input, append, remove, out=out) - except uex.valueMayNotChange, e: - print >> out, unicode(e[0]) + except uex.valueMayNotChange, ex: + print >> out, unicode(ex[0]) raise Failed() if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options: try: @@ -926,11 +926,11 @@ def _doit(arglist, out=sys.stdout): except uex.invalidDhcpEntry: print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' raise Failed() - except uex.circularGroupDependency, e: - print >> out, 'E: circular group dependency detected: %s' % e + except uex.circularGroupDependency, ex: + print >> out, 'E: circular group dependency detected: %s' % ex raise Failed() - except uex.valueInvalidSyntax, e: - print >> out, 'E: Invalid Syntax: %s' % e + except uex.valueInvalidSyntax, ex: + print >> out, 'E: Invalid Syntax: %s' % ex raise Failed() if policy_reference: @@ -990,8 +990,8 @@ def _doit(arglist, out=sys.stdout): if recursive: try: object.remove(recursive) - except uex.ldapError, msg: - print >> out, str(msg) + except uex.ldapError, ex: + print >> out, ex raise Failed() else: try: @@ -1077,11 +1077,11 @@ def _doit(arglist, out=sys.stdout): print >> out, '' print >> out, '' - except uex.ldapError, errmsg: - print >> out, '%s' % (errmsg,) + except uex.ldapError, ex: + print >> out, ex raise Failed() - except uex.valueInvalidSyntax, errmsg: - print >> out, '%s' % (errmsg.message,) + except uex.valueInvalidSyntax, ex: + print >> out, ex.message raise Failed() else: print >> out, "Unknown or no action defined" -- --- .../modules/univention/admincli/admin.py | 148 +++++++++++++++++++++ 1 file changed, 148 insertions(+) --- a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py +++ a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py @@ -32,6 +32,7 @@ from textwrap import dedent import sys +from argparse import ArgumentParser import getopt import re import base64 @@ -56,6 +57,153 @@ univention.admin.modules.update() univention.admin.syntax.update_choices() +def parse_commandline(): + usage = dedent("""\ + %(prog)s module action [arguments] + %(prog)s [--help] [--version] + """) + description = dedent("""\ + univention-directory-manager is a tool to handle the configuration for UCS + on command line level. + Use "univention-directory-manager modules" for a list of available modules. + """) + version = "%(prog)s @%@package_version@%@" + parser = ArgumentParser( + usage=usage, + description=description, + prog="univention-directory-manager") + parser.add_argument("-?", action="help") + parser.add_argument("--version", action="version", version=version) + + general_opt = parser.add_argument_group("General options") + general_opt.add_argument( + "--logfile", + dest="logfile", + default='/var/log/univention/directory-manager-cmd.log', + help="path and name of the logfile to be used") + general_opt.add_argument( + "--binddn", + dest="binddn", + help="bind DN") + general_opt.add_argument( + "--bindpwd", + dest="bindpwd", + help="bind password") + general_opt.add_argument( + "--bindpwdfile", + dest="bindpwdfile", + help="file containing bind password") + general_opt.add_argument( + "--tls", + dest="tls", type=int, + default=2, choices=range(3), + help="0 (no); 1 (try); 2 (must)") + + subparsers = parser.add_subparsers( + title="sub-commands", + description="valid subcommands", + help="additional help") + + create_opt = subparsers.add_parser("modules", help="List available modules") + + create_opt = subparsers.add_parser("create", help="Create a new object") + create_opt.add_argument( + "--position", + dest="position", + help="Set position in tree") + create_opt.add_argument( + "--set", + action="append", dest="set", required=True, + help="Set variable to value, e.g. foo=bar") + create_opt.add_argument( + "--superordinate", + dest="superordinate", + help="Use superordinate module") + create_opt.add_argument( + "--option", + action="append", dest="option", + help="Use only given module options") + create_opt.add_argument( + "--policy-reference", + action="append", dest="policy_reference", + help="Reference to policy given by DN") + create_opt.add_argument( + "--ignore_exists", + action="store_true", dest="ignore_exists", + help="Ignore already existing object") + + modify_opt = subparsers.add_parser("modify", help="Modify an existing object") + modify_opt.add_argument( + "--dn", + dest="dn", required=True, + help="Edit object with DN") + modify_opt.add_argument( + "--set", + action="append", dest="set", + help="Set variable to value, e.g. foo=bar") + modify_opt.add_argument( + "--append", + action="append", dest="append", + help="Append value to variable, e.g. foo=bar") + modify_opt.add_argument( + "--remove", + action="append", dest="remove", + help="Remove value from variable, e.g. foo=bar") + modify_opt.add_argument( + "--option", + action="append", dest="option", + help="Append the module options") + modify_opt.add_argument( + "--policy-reference", + action="append", dest="policy_reference", + help="Reference to policy given by DN") + modify_opt.add_argument( + "--policy-dereference", + action="append", dest="policy_dereference", + help="Remove reference to policy given by DN") + + remove_opt = subparsers.add_parser("remove", help="Remove an existing object") + remove_opt.add_argument( + "--dn", + dest="dn", + help="Remove object with DN") + remove_opt.add_argument( + "--superordinate", + dest="superordinate", + help="Use superordinate module") + remove_opt.add_argument( + "--filter", + dest="filter", + help="Lookup filter e.g. foo=bar") + remove_opt.add_argument( + "--remove_referring", + action="store_true", dest="remove_referring", + help="Remove referring objects") + + list_opt = subparsers.add_parser("list", help="List objects") + list_opt.add_argument( + "--filter", + dest="filter", + help="Lookup filter e.g. foo=bar") + list_opt.add_argument( + "--policies", + dest="policies", type=int, choices=range(2), + help="List policy-based settings: 0:short, 1:long (with policy-DN)") + + move_opt = subparsers.add_parser("move", help="Move object in directory tree") + move_opt.add_argument( + "--dn", + dest="dn", required=True, + help="Move object with DN") + move_opt.add_argument( + "--position", + dest="position", required=True, + help="Move to position in tree") + + args = parser.parse_args() + return args + + class Failed(Exception): def __str__(self): return "OPERATION FAILED" --