From 88d997a63e93c4d0ed20e39a962d34b74c90b90c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Oct 2011 00:36:44 +0200 Subject: samba-tool: Use self.outf in a few more places. Autobuild-User: Jelmer Vernooij Autobuild-Date: Thu Oct 13 05:06:52 CEST 2011 on sn-devel-104 --- source4/scripting/python/samba/netcmd/__init__.py | 12 ++--- source4/scripting/python/samba/netcmd/dbcheck.py | 13 ++--- source4/scripting/python/samba/netcmd/dsacl.py | 4 +- source4/scripting/python/samba/netcmd/fsmo.py | 4 +- source4/scripting/python/samba/netcmd/gpo.py | 64 ++++++++++++----------- source4/scripting/python/samba/netcmd/group.py | 15 ++++-- source4/scripting/python/samba/netcmd/ldapcmp.py | 33 +++++++----- source4/scripting/python/samba/netcmd/ntacl.py | 4 +- source4/scripting/python/samba/netcmd/rodc.py | 2 +- source4/scripting/python/samba/netcmd/spn.py | 11 ++-- source4/scripting/python/samba/netcmd/testparm.py | 4 +- source4/scripting/python/samba/netcmd/time.py | 2 +- source4/scripting/python/samba/netcmd/user.py | 24 ++++----- 13 files changed, 104 insertions(+), 88 deletions(-) diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py index 49e03800d6..33ed3d5578 100644 --- a/source4/scripting/python/samba/netcmd/__init__.py +++ b/source4/scripting/python/samba/netcmd/__init__.py @@ -100,7 +100,7 @@ class Command(object): return parser, optiongroups def message(self, text): - print text + self.outf.write(text+"\n") def _run(self, *argv): parser, optiongroups = self._create_parser() @@ -162,17 +162,17 @@ class SuperCommand(Command): usage = "samba-tool " else: usage = "samba-tool %s " % myname - print "Usage: %s [options]" %usage - print "Available subcommands:" + self.outf.write("Usage: %s [options]\n" % usage) + self.outf.write("Available subcommands:\n") subcmds = self.subcommands.keys() subcmds.sort() - max_length = max(map(lambda c: len(c), subcmds)) + max_length = max([len(c) for c in subcmds]) for cmd in subcmds: - print " %*s - %s" % (-max_length, cmd, self.subcommands[cmd].description) + self.outf.write(" %*s - %s\n" % (-max_length, cmd, self.subcommands[cmd].description)) if subcommand in [None]: raise CommandError("You must specify a subcommand") if subcommand in ['help', '-h', '--help']: - print "For more help on a specific subcommand, please type: %s (-h|--help)" % usage + self.outf.write("For more help on a specific subcommand, please type: %s (-h|--help)\n" % usage) return 0 raise CommandError("No such subcommand '%s'" % subcommand) diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py b/source4/scripting/python/samba/netcmd/dbcheck.py index 7840a61725..44f3dedf34 100644 --- a/source4/scripting/python/samba/netcmd/dbcheck.py +++ b/source4/scripting/python/samba/netcmd/dbcheck.py @@ -56,8 +56,10 @@ class cmd_dbcheck(Command): type=str, metavar="URL", dest="H"), ] - def run(self, DN=None, H=None, verbose=False, fix=False, yes=False, cross_ncs=False, quiet=False, - scope="SUB", credopts=None, sambaopts=None, versionopts=None, attrs=None, reindex=False): + def run(self, DN=None, H=None, verbose=False, fix=False, yes=False, + cross_ncs=False, quiet=False, + scope="SUB", credopts=None, sambaopts=None, versionopts=None, + attrs=None, reindex=False): lp = sambaopts.get_loadparm() @@ -77,7 +79,7 @@ class cmd_dbcheck(Command): samdb_schema = SamDB(session_info=system_session(), url=None, credentials=creds, lp=lp) - scope_map = { "SUB": ldb.SCOPE_SUBTREE, "BASE":ldb.SCOPE_BASE, "ONE":ldb.SCOPE_ONELEVEL } + scope_map = { "SUB": ldb.SCOPE_SUBTREE, "BASE": ldb.SCOPE_BASE, "ONE":ldb.SCOPE_ONELEVEL } scope = scope.upper() if not scope in scope_map: raise CommandError("Unknown scope %s" % scope) @@ -95,7 +97,6 @@ class cmd_dbcheck(Command): attrs = attrs.split() started_transaction = False - if yes and fix: samdb.transaction_start() started_transaction = True @@ -104,10 +105,10 @@ class cmd_dbcheck(Command): fix=fix, yes=yes, quiet=quiet) if reindex: - print("Re-indexing...") + self.outf.write("Re-indexing...\n") error_count = 0 if chk.reindex_database(): - print("completed re-index OK") + self.outf.write("completed re-index OK\n") else: error_count = chk.check_database(DN=DN, scope=search_scope, controls=controls, attrs=attrs) diff --git a/source4/scripting/python/samba/netcmd/dsacl.py b/source4/scripting/python/samba/netcmd/dsacl.py index 78dae43764..97d4eb8534 100644 --- a/source4/scripting/python/samba/netcmd/dsacl.py +++ b/source4/scripting/python/samba/netcmd/dsacl.py @@ -129,8 +129,8 @@ class cmd_dsacl_set(Command): def print_new_acl(self, samdb, object_dn): desc = self.read_descriptor(samdb, object_dn) desc_sddl = desc.as_sddl(self.get_domain_sid(samdb)) - print "new descriptor for %s:" % object_dn - print desc_sddl + self.outf.write("new descriptor for %s:\n" % object_dn) + self.outf.write(desc_sddl + "\n") def run(self, car, action, objectdn, trusteedn, sddl, H=None, credopts=None, sambaopts=None, versionopts=None): diff --git a/source4/scripting/python/samba/netcmd/fsmo.py b/source4/scripting/python/samba/netcmd/fsmo.py index 06a2de1c2c..e8e24b2de1 100644 --- a/source4/scripting/python/samba/netcmd/fsmo.py +++ b/source4/scripting/python/samba/netcmd/fsmo.py @@ -95,7 +95,7 @@ all=all of the above"""), samdb.modify(m) except LdbError, (num, msg): raise CommandError("Failed to initiate role seize of '%s' role: %s" % (role, msg)) - print("FSMO transfer of '%s' role successful" % role) + self.outf.write("FSMO transfer of '%s' role successful\n" % role) def run(self, force=None, H=None, role=None, credopts=None, sambaopts=None, versionopts=None): @@ -231,7 +231,7 @@ all=all of the above"""), samdb.modify(m) except LdbError, (num, msg): raise CommandError("Failed to initiate transfer of '%s' role: %s" % (role, msg)) - print("FSMO transfer of '%s' role successful" % role) + self.outf.write("FSMO transfer of '%s' role successful\n" % role) def run(self, force=None, H=None, role=None, credopts=None, sambaopts=None, versionopts=None): diff --git a/source4/scripting/python/samba/netcmd/gpo.py b/source4/scripting/python/samba/netcmd/gpo.py index 8b96d37d50..0d96dbc56f 100644 --- a/source4/scripting/python/samba/netcmd/gpo.py +++ b/source4/scripting/python/samba/netcmd/gpo.py @@ -256,13 +256,13 @@ class cmd_listall(Command): msg = get_gpo_info(self.samdb, None) for m in msg: - print("GPO : %s" % m['name'][0]) - print("display name : %s" % m['displayName'][0]) - print("path : %s" % m['gPCFileSysPath'][0]) - print("dn : %s" % m.dn) - print("version : %s" % attr_default(m, 'versionNumber', '0')) - print("flags : %s" % gpo_flags_string(int(attr_default(m, 'flags', 0)))) - print("") + self.outf.write("GPO : %s\n" % m['name'][0]) + self.outf.write("display name : %s\n" % m['displayName'][0]) + self.outf.write("path : %s\n" % m['gPCFileSysPath'][0]) + self.outf.write("dn : %s\n" % m.dn) + self.outf.write("version : %s\n" % attr_default(m, 'versionNumber', '0')) + self.outf.write("flags : %s\n" % gpo_flags_string(int(attr_default(m, 'flags', 0)))) + self.outf.write("\n") class cmd_list(Command): @@ -331,7 +331,8 @@ class cmd_list(Command): attrs=['name', 'displayName', 'flags', 'ntSecurityDescriptor']) except Exception: - print("Failed to fetch gpo object %s" % g['dn']) + self.outf.write("Failed to fetch gpo object %s\n" % + g['dn']) continue secdesc_ndr = gmsg[0]['ntSecurityDescriptor'][0] @@ -343,7 +344,7 @@ class cmd_list(Command): dcerpc.security.SEC_ADS_LIST | dcerpc.security.SEC_ADS_READ_PROP) except RuntimeError: - print("Failed access check on %s" % msg.dn) + self.outf.write("Failed access check on %s\n" % msg.dn) continue # check the flags on the GPO @@ -368,9 +369,9 @@ class cmd_list(Command): else: msg_str = 'user' - print("GPOs for %s %s" % (msg_str, username)) + self.outf.write("GPOs for %s %s\n" % (msg_str, username)) for g in gpos: - print(" %s %s" % (g[0], g[1])) + self.outf.write(" %s %s\n" % (g[0], g[1])) class cmd_show(Command): @@ -407,14 +408,14 @@ class cmd_show(Command): secdesc_ndr = msg['ntSecurityDescriptor'][0] secdesc = ndr_unpack(dcerpc.security.descriptor, secdesc_ndr) - print("GPO : %s" % msg['name'][0]) - print("display name : %s" % msg['displayName'][0]) - print("path : %s" % msg['gPCFileSysPath'][0]) - print("dn : %s" % msg.dn) - print("version : %s" % attr_default(msg, 'versionNumber', '0')) - print("flags : %s" % gpo_flags_string(int(attr_default(msg, 'flags', 0)))) - print("ACL : %s" % secdesc.as_sddl()) - print("") + self.outf.write("GPO : %s\n" % msg['name'][0]) + self.outf.write("display name : %s\n" % msg['displayName'][0]) + self.outf.write("path : %s\n" % msg['gPCFileSysPath'][0]) + self.outf.write("dn : %s\n" % msg.dn) + self.outf.write("version : %s\n" % attr_default(msg, 'versionNumber', '0')) + self.outf.write("flags : %s\n" % gpo_flags_string(int(attr_default(msg, 'flags', 0)))) + self.outf.write("ACL : %s\n" % secdesc.as_sddl()) + self.outf.write("\n") class cmd_getlink(Command): @@ -452,16 +453,16 @@ class cmd_getlink(Command): raise CommandError("Could not find Container DN %s (%s)" % container_dn, e) if 'gPLink' in msg: - print("GPO(s) linked to DN %s" % container_dn) + self.outf.write("GPO(s) linked to DN %s\n" % container_dn) gplist = parse_gplink(msg['gPLink'][0]) for g in gplist: msg = get_gpo_info(self.samdb, dn=g['dn']) - print(" GPO : %s" % msg[0]['name'][0]) - print(" Name : %s" % msg[0]['displayName'][0]) - print(" Options : %s" % gplink_options_string(g['options'])) - print("") + self.outf.write(" GPO : %s\n" % msg[0]['name'][0]) + self.outf.write(" Name : %s\n" % msg[0]['displayName'][0]) + self.outf.write(" Options : %s\n" % gplink_options_string(g['options'])) + self.outf.write("\n") else: - print("No GPO(s) linked to DN=%s" % container_dn) + self.outf.write("No GPO(s) linked to DN=%s\n" % container_dn) class cmd_setlink(Command): @@ -548,7 +549,7 @@ class cmd_setlink(Command): except Exception, e: raise CommandError("Error adding GPO Link", e) - print("Added/Updated GPO link") + self.outf.write("Added/Updated GPO link\n") cmd_getlink().run(container_dn, H, sambaopts, credopts, versionopts) @@ -617,7 +618,7 @@ class cmd_dellink(Command): except Exception, e: raise CommandError("Error Removing GPO Link (%s)" % e) - print("Deleted GPO link.") + self.outf.write("Deleted GPO link.\n") cmd_getlink().run(container_dn, H, sambaopts, credopts, versionopts) @@ -660,9 +661,9 @@ class cmd_getinheritance(Command): inheritance = int(msg['gPOptions'][0]) if inheritance == dsdb.GPO_BLOCK_INHERITANCE: - print("Container has GPO_BLOCK_INHERITANCE") + self.outf.write("Container has GPO_BLOCK_INHERITANCE\n") else: - print("Container has GPO_INHERIT") + self.outf.write("Container has GPO_INHERIT\n") class cmd_setinheritance(Command): @@ -783,8 +784,9 @@ class cmd_fetch(Command): os.mkdir(gpodir) copy_directory_remote_to_local(conn, sharepath, gpodir) except Exception, e: + # FIXME: Catch more specific exception raise CommandError("Error copying GPO from DC", e) - print('GPO copied to %s' % gpodir) + self.outf.write('GPO copied to %s\n' % gpodir) class cmd_create(Command): @@ -951,7 +953,7 @@ class cmd_create(Command): except Exception, e: raise CommandError("Error setting ACL on GPT", e) - print "GPO '%s' created as %s" % (displayname, gpo) + self.outf.write("GPO '%s' created as %s\n" % (displayname, gpo)) class cmd_gpo(SuperCommand): diff --git a/source4/scripting/python/samba/netcmd/group.py b/source4/scripting/python/samba/netcmd/group.py index 90bee5f636..db2a6d6269 100644 --- a/source4/scripting/python/samba/netcmd/group.py +++ b/source4/scripting/python/samba/netcmd/group.py @@ -80,8 +80,9 @@ class cmd_group_add(Command): samdb.newgroup(groupname, groupou=groupou, grouptype = gtype, description=description, mailaddress=mail_address, notes=notes) except Exception, e: + # FIXME: catch more specific exception raise CommandError('Failed to create group "%s"' % groupname, e) - print("Added group %s" % groupname) + self.outf.write("Added group %s\n" % groupname) class cmd_group_delete(Command): @@ -106,8 +107,9 @@ class cmd_group_delete(Command): credentials=creds, lp=lp) samdb.deletegroup(groupname) except Exception, e: + # FIXME: catch more specific exception raise CommandError('Failed to remove group "%s"' % groupname, e) - print("Deleted group %s" % groupname) + self.outf.write("Deleted group %s\n" % groupname) class cmd_group_add_members(Command): @@ -133,8 +135,10 @@ class cmd_group_add_members(Command): credentials=creds, lp=lp) samdb.add_remove_group_members(groupname, listofmembers, add_members_operation=True) except Exception, e: - raise CommandError('Failed to add members "%s" to group "%s"' % (listofmembers, groupname), e) - print("Added members to group %s" % groupname) + # FIXME: catch more specific exception + raise CommandError('Failed to add members "%s" to group "%s"' % ( + listofmembers, groupname), e) + self.outf.write("Added members to group %s\n" % groupname) class cmd_group_remove_members(Command): @@ -160,8 +164,9 @@ class cmd_group_remove_members(Command): credentials=creds, lp=lp) samdb.add_remove_group_members(groupname, listofmembers, add_members_operation=False) except Exception, e: + # FIXME: Catch more specific exception raise CommandError('Failed to remove members "%s" from group "%s"' % (listofmembers, groupname), e) - print("Removed members from group %s" % groupname) + self.outf.write("Removed members from group %s\n" % groupname) class cmd_group(SuperCommand): diff --git a/source4/scripting/python/samba/netcmd/ldapcmp.py b/source4/scripting/python/samba/netcmd/ldapcmp.py index cd81aa33d8..7805eca6cf 100755 --- a/source4/scripting/python/samba/netcmd/ldapcmp.py +++ b/source4/scripting/python/samba/netcmd/ldapcmp.py @@ -85,11 +85,15 @@ class LDAPBase(object): # Log some domain controller specific place-holers that are being used # when compare content of two DCs. Uncomment for DEBUG purposes. if self.two_domains and not self.quiet: - print "\n* Place-holders for %s:" % self.host - print 4*" " + "${DOMAIN_DN} => %s" % self.base_dn - print 4*" " + "${DOMAIN_NETBIOS} => %s" % self.domain_netbios - print 4*" " + "${SERVER_NAME} => %s" % self.server_names - print 4*" " + "${DOMAIN_NAME} => %s" % self.domain_name + self.outf.write("\n* Place-holders for %s:\n" % self.host) + self.outf.write(4*" " + "${DOMAIN_DN} => %s\n" % + self.base_dn) + self.outf.write(4*" " + "${DOMAIN_NETBIOS} => %s\n" % + self.domain_netbios) + self.outf.write(4*" " + "${SERVER_NAME} => %s\n" % + self.server_names) + self.outf.write(4*" " + "${DOMAIN_NAME} => %s\n" % + self.domain_name) def find_domain_sid(self): res = self.ldb.search(base=self.base_dn, expression="(objectClass=*)", scope=SCOPE_BASE) @@ -493,7 +497,7 @@ class LDAPObject(object): Log on the screen if there is no --quiet oprion set """ if not self.quiet: - print msg + self.outf.write(msg+"\n") def fix_dn(self, s): res = "%s" % s @@ -665,6 +669,7 @@ class LDAPObject(object): class LDAPBundel(object): + def __init__(self, connection, context, dn_list=None, filter_list=None): self.con = connection self.two_domains = self.con.two_domains @@ -705,7 +710,7 @@ class LDAPBundel(object): Log on the screen if there is no --quiet oprion set """ if not self.quiet: - print msg + self.outf.write(msg+"\n") def update_size(self): self.size = len(self.dn_list) @@ -820,7 +825,7 @@ class LDAPBundel(object): try: res = self.con.ldb.search(base=self.search_base, scope=self.search_scope, attrs=["dn"]) except LdbError, (enum, estr): - print("Failed search of base=%s" % self.search_base) + self.outf.write("Failed search of base=%s\n" % self.search_base) raise for x in res: dn_list.append(x["dn"].get_linearized()) @@ -842,6 +847,7 @@ class LDAPBundel(object): self.log( "".join([str("\n" + 4*" " + x) for x in self.summary["df_value_attrs"]]) ) self.summary["df_value_attrs"] = [] + class cmd_ldapcmp(Command): """compare two ldap databases""" synopsis = "%prog ldapcmp (domain|configuration|schema) [options]" @@ -942,22 +948,23 @@ class cmd_ldapcmp(Command): status = 0 for context in contexts: if not quiet: - print "\n* Comparing [%s] context..." % context + self.outf.write("\n* Comparing [%s] context...\n" % context) b1 = LDAPBundel(con1, context=context, filter_list=filter_list) b2 = LDAPBundel(con2, context=context, filter_list=filter_list) if b1 == b2: if not quiet: - print "\n* Result for [%s]: SUCCESS" % context + self.outf.write("\n* Result for [%s]: SUCCESS\n" % + context) else: if not quiet: - print "\n* Result for [%s]: FAILURE" % context + self.outf.write("\n* Result for [%s]: FAILURE\n" % context) if not descriptor: assert len(b1.summary["df_value_attrs"]) == len(b2.summary["df_value_attrs"]) b2.summary["df_value_attrs"] = [] - print "\nSUMMARY" - print "---------" + self.outf.write("\nSUMMARY\n") + self.outf.write("---------\n") b1.print_summary() b2.print_summary() # mark exit status as FAILURE if a least one comparison failed diff --git a/source4/scripting/python/samba/netcmd/ntacl.py b/source4/scripting/python/samba/netcmd/ntacl.py index d93835bda1..1948309ca8 100644 --- a/source4/scripting/python/samba/netcmd/ntacl.py +++ b/source4/scripting/python/samba/netcmd/ntacl.py @@ -65,7 +65,6 @@ class cmd_ntacl_set(Command): except Exception, e: raise CommandError("Unable to read domain SID from configuration files", e) attrs = ["objectSid"] - print lp.get("realm") res = ldb.search(expression="(objectClass=*)", base="flatname=%s,cn=Primary Domains" % lp.get("workgroup"), scope=SCOPE_BASE, attrs=attrs) @@ -97,12 +96,11 @@ class cmd_ntacl_get(Command): acl = getntacl(lp, file, xattr_backend, eadb_file) if as_sddl: anysid = security.dom_sid(security.SID_NT_SELF) - print acl.info.as_sddl(anysid) + self.outf.write(acl.info.as_sddl(anysid)+"\n") else: acl.dump() - class cmd_ntacl(SuperCommand): """NT ACLs manipulation""" diff --git a/source4/scripting/python/samba/netcmd/rodc.py b/source4/scripting/python/samba/netcmd/rodc.py index 67c23dcf6f..b2a5e3f720 100644 --- a/source4/scripting/python/samba/netcmd/rodc.py +++ b/source4/scripting/python/samba/netcmd/rodc.py @@ -90,7 +90,7 @@ class cmd_rodc_preload(Command): source_dsa_invocation_id = misc.GUID(local_samdb.schema_format_value("objectGUID", res[0]["invocationId"][0])) dn = self.get_dn(samdb, account) - print "Replicating DN %s" % dn + self.outf.write("Replicating DN %s\n" % dn) destination_dsa_guid = misc.GUID(local_samdb.get_ntds_GUID()) diff --git a/source4/scripting/python/samba/netcmd/spn.py b/source4/scripting/python/samba/netcmd/spn.py index 6c36f6ca4c..614710c973 100644 --- a/source4/scripting/python/samba/netcmd/spn.py +++ b/source4/scripting/python/samba/netcmd/spn.py @@ -50,7 +50,7 @@ class cmd_spn_list(Command): # TODO once I understand how, use the domain info to naildown # to the correct domain (cleaneduser, realm, domain) = _get_user_realm_domain(user) - print cleaneduser + self.outf.write(cleaneduser+"\n") res = sam.search(expression="samaccountname=%s" % ldb.binary_encode(cleaneduser), scope=ldb.SCOPE_SUBTREE, attrs=["servicePrincipalName"]) @@ -59,11 +59,14 @@ class cmd_spn_list(Command): found = False flag = ldb.FLAG_MOD_ADD if spns != None: - print "User %s has the following servicePrincipalName: " % str(res[0].dn) + self.outf.write( + "User %s has the following servicePrincipalName: \n" % + res[0].dn) for e in spns: - print "\t %s" % (str(e)) + self.outf.write("\t %s\n" % e) else: - print "User %s has no servicePrincipalName" % str(res[0].dn) + self.outf.write("User %s has no servicePrincipalName" % + res[0].dn) else: raise CommandError("User %s not found" % user) diff --git a/source4/scripting/python/samba/netcmd/testparm.py b/source4/scripting/python/samba/netcmd/testparm.py index b9979770e6..9de6fdfa20 100755 --- a/source4/scripting/python/samba/netcmd/testparm.py +++ b/source4/scripting/python/samba/netcmd/testparm.py @@ -106,10 +106,10 @@ class cmd_testparm(Command): if parameter_name is None: lp[section_name].dump(sys.stdout, lp.default_service, verbose) else: - print lp.get(parameter_name, section_name) + self.outf.write(lp.get(parameter_name, section_name)+"\n") else: if not suppress_prompt: - print "Press enter to see a dump of your service definitions" + self.outf.write("Press enter to see a dump of your service definitions\n") sys.stdin.readline() lp.dump(sys.stdout, verbose) if valid: diff --git a/source4/scripting/python/samba/netcmd/time.py b/source4/scripting/python/samba/netcmd/time.py index 9b52094484..31a6f7c627 100644 --- a/source4/scripting/python/samba/netcmd/time.py +++ b/source4/scripting/python/samba/netcmd/time.py @@ -39,4 +39,4 @@ class cmd_time(Command): net = Net(creds, lp, server=credopts.ipaddress) if server_name is None: server_name = common.netcmd_dnsname(lp) - print net.time(server_name) + self.outf.write(net.time(server_name)+"\n") diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py index 5af80ffd74..215fd15533 100644 --- a/source4/scripting/python/samba/netcmd/user.py +++ b/source4/scripting/python/samba/netcmd/user.py @@ -101,8 +101,7 @@ class cmd_user_add(Command): except Exception, e: raise CommandError("Failed to add user '%s': " % username, e) - print("User '%s' created successfully" % username) - + self.outf.write("User '%s' created successfully\n" % username) class cmd_user_delete(Command): @@ -128,8 +127,7 @@ class cmd_user_delete(Command): samdb.deleteuser(username) except Exception, e: raise CommandError('Failed to remove user "%s"' % username, e) - print("Deleted user %s" % username) - + self.outf.write("Deleted user %s\n" % username) class cmd_user_enable(Command): @@ -162,8 +160,7 @@ class cmd_user_enable(Command): samdb.enable_account(filter) except Exception, msg: raise CommandError("Failed to enable user '%s': %s" % (username or filter, msg)) - print("Enabled user '%s'" % (username or filter)) - + self.outf.write("Enabled user '%s'\n" % (username or filter)) class cmd_user_setexpiry(Command): @@ -198,9 +195,11 @@ class cmd_user_setexpiry(Command): try: samdb.setexpiry(filter, days*24*3600, no_expiry_req=noexpiry) except Exception, msg: - raise CommandError("Failed to set expiry for user '%s': %s" % (username or filter, msg)) - print("Set expiry for user '%s' to %u days" % (username or filter, days)) - + # FIXME: Catch more specific exception + raise CommandError("Failed to set expiry for user '%s': %s" % ( + username or filter, msg)) + self.outf.write("Set expiry for user '%s' to %u days\n" % ( + username or filter, days)) class cmd_user_password(Command): @@ -232,9 +231,9 @@ class cmd_user_password(Command): try: net.change_password(password) except Exception, msg: + # FIXME: catch more specific exception raise CommandError("Failed to change password : %s" % msg) - print "Changed password OK" - + self.outf.write("Changed password OK\n") class cmd_user_setpassword(Command): @@ -282,8 +281,9 @@ class cmd_user_setpassword(Command): force_change_at_next_login=must_change_at_next_login, username=username) except Exception, msg: + # FIXME: catch more specific exception raise CommandError("Failed to set password for user '%s': %s" % (username or filter, msg)) - print "Changed password OK" + self.outf.write("Changed password OK\n") -- cgit