pynet: Raise proper exceptions rather than invoking sys.exit.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 18 May 2010 22:26:56 +0000 (00:26 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 19 May 2010 17:35:22 +0000 (19:35 +0200)
source4/scripting/python/samba/netcmd/newuser.py
source4/scripting/python/samba/netcmd/setpassword.py

index 9ffc0e6525468a8f4a1eaad2f99de4e8251b9cf6..bb5537aaf020373decc79fe6bdff406d3ef1c902 100644 (file)
@@ -20,8 +20,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import samba.getopt as options
-from samba.netcmd import Command, Option
-import sys, ldb
+from samba.netcmd import Command, CommandError, Option
+import ldb
 
 from getpass import getpass
 from samba.auth import system_session
@@ -61,6 +61,6 @@ class cmd_newuser(Command):
             samdb.newuser(username, password,
                           force_password_change_at_next_login_req=must_change_at_next_login)
         except ldb.LdbError, (num, msg):
-            print('Failed to create user "%s" : %s' % (username, msg))
-            sys.exit(1)
+            raise CommandError('Failed to create user "%s" : %s' % (
+                username, msg))
 
index 098b3cb9b89dc9d110127ba1bcc791400f760410..d51e8ea42a450db2f5ef8b6100c459d00fa17b0e 100644 (file)
@@ -22,7 +22,6 @@
 
 import samba.getopt as options
 from samba.netcmd import Command, CommandError, Option
-import sys
 from getpass import getpass
 from samba.auth import system_session
 from samba.samdb import SamDB
@@ -73,6 +72,5 @@ class cmd_setpassword(Command):
                               force_change_at_next_login=must_change_at_next_login,
                               username=username)
         except:
-            print('Failed to set password for user "%s"' % username)
-            sys.exit(1)
-
+            raise CommandError('Failed to set password for user "%s"' %
+                username)