diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-11-29 14:15:57 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-11-29 18:04:42 +1100 |
commit | 37bfc4ec384df71a4cb1c19ceb136fecd3b9afc6 (patch) | |
tree | e44efedee115beac377d1fc9ab3a22c5e6cc2cee /source4/scripting/python/samba/netcmd/gpo.py | |
parent | 62506903101e8e8e1cfc6c70fee245f97c646844 (diff) | |
download | samba-37bfc4ec384df71a4cb1c19ceb136fecd3b9afc6.tar.gz samba-37bfc4ec384df71a4cb1c19ceb136fecd3b9afc6.tar.xz samba-37bfc4ec384df71a4cb1c19ceb136fecd3b9afc6.zip |
s4-samba-tool: fixed exception handling in subcommands
this switches to the new pattern of:
except Exception, e:
raise CommandError("some error message", e)
Diffstat (limited to 'source4/scripting/python/samba/netcmd/gpo.py')
-rw-r--r-- | source4/scripting/python/samba/netcmd/gpo.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/source4/scripting/python/samba/netcmd/gpo.py b/source4/scripting/python/samba/netcmd/gpo.py index 90b7a5efaa0..5e8748adc53 100644 --- a/source4/scripting/python/samba/netcmd/gpo.py +++ b/source4/scripting/python/samba/netcmd/gpo.py @@ -41,8 +41,8 @@ def samdb_connect(ctx): ctx.samdb = SamDB(url=ctx.url, session_info=system_session(), credentials=ctx.creds, lp=ctx.lp) - except Exception, estr: - raise CommandError("LDAP connection to %s failed - %s" % (ctx.url, estr)) + except Exception, e: + raise CommandError("LDAP connection to %s failed " % ctx.url, e) def attr_default(msg, attrname, default): @@ -114,9 +114,12 @@ class cmd_listall(Command): ("GPO_FLAG_USER_DISABLE", dsdb.GPO_FLAG_USER_DISABLE ), ( "GPO_FLAG_MACHINE_DISABLE", dsdb.GPO_FLAG_MACHINE_DISABLE ) ] - msg = self.samdb.search(base=policies_dn, scope=ldb.SCOPE_ONELEVEL, - expression="(objectClass=groupPolicyContainer)", - attrs=['nTSecurityDescriptor', 'versionNumber', 'flags', 'name', 'displayName', 'gPCFileSysPath']) + try: + msg = self.samdb.search(base=policies_dn, scope=ldb.SCOPE_ONELEVEL, + expression="(objectClass=groupPolicyContainer)", + attrs=['nTSecurityDescriptor', 'versionNumber', 'flags', 'name', 'displayName', 'gPCFileSysPath']) + except Exception, e: + raise CommandError("Failed to list policies in %s" % policies_dn, e) for m in msg: print("GPO : %s" % m['name'][0]) print("display name : %s" % m['displayName'][0]) @@ -158,15 +161,15 @@ class cmd_list(Command): try: user_dn = self.samdb.search(expression='(&(samAccountName=%s)(objectclass=User))' % username)[0].dn - except Exception, estr: - raise CommandError("Failed to find user %s - %s" % (username, estr)) + except Exception, e: + raise CommandError("Failed to find user %s" % username, e) # check if its a computer account try: msg = self.samdb.search(base=user_dn, scope=ldb.SCOPE_BASE, attrs=['objectClass'])[0] is_computer = 'computer' in msg['objectClass'] - except Exception, estr: - raise CommandError("Failed to find objectClass for user %s - %s" % (username, estr)) + except Exception, e: + raise CommandError("Failed to find objectClass for user %s" % username, e) print("TODO: get user token") # token = self.samdb.get_user_token(username) |