>From eafd696c0290211f0c7e18148674f41012f2d14f Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Wed, 28 Sep 2016 21:35:51 +1300 Subject: [PATCH] Fix for bug 12292 Signed-off-by: Douglas Bagnall --- python/samba/netcmd/user.py | 4 +++- python/samba/samdb.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py index 5adc287..bc2d261 100644 --- a/python/samba/netcmd/user.py +++ b/python/samba/netcmd/user.py @@ -410,9 +410,11 @@ Example2 shows how to delete a user in the domain against the local server. su samdb = SamDB(url=H, session_info=system_session(), credentials=creds, lp=lp) samdb.deleteuser(username) + self.outf.write("Deleted user %s\n" % username) + except samdb.NotFoundError: + self.outf.write("Unable to find user %s\n" % username) except Exception, e: raise CommandError('Failed to remove user "%s"' % username, e) - self.outf.write("Deleted user %s\n" % username) class cmd_user_list(Command): diff --git a/python/samba/samdb.py b/python/samba/samdb.py index 3d7ea3e..441bcb3 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -34,6 +34,8 @@ from samba.common import normalise_int32 __docformat__ = "restructuredText" +class NotFoundError(Exception): + pass class SamDB(samba.Ldb): """The SAM database.""" @@ -476,7 +478,7 @@ member: %s target = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE, expression=filter, attrs=[]) if len(target) == 0: - raise Exception('Unable to find user "%s"' % username) + raise NotFoundError('Unable to find user "%s"' % username) assert(len(target) == 1) self.delete(target[0].dn) except: -- 2.1.4