summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorGiampaolo Lauria <lauria2@yahoo.com>2011-07-18 11:30:23 -0400
committerAndrew Tridgell <tridge@samba.org>2011-07-21 11:44:30 +1000
commit903ec440c40bcbf040fc01cab339e42cbf3fdf5c (patch)
tree295b00f01393ca8b336101439a29beaed4732183 /source4/scripting/python
parent8e0a86056139281b2e1ad7763e51cf804e38a77e (diff)
downloadsamba-903ec440c40bcbf040fc01cab339e42cbf3fdf5c.tar.gz
samba-903ec440c40bcbf040fc01cab339e42cbf3fdf5c.tar.bz2
samba-903ec440c40bcbf040fc01cab339e42cbf3fdf5c.zip
samba-tool: Fix error handling in SuperCommand class
Created show_command_error method to handle errors in SuperCommand Removed statement in SuperCommand to raise exception Signed-off-by: Andrew Tridgell <tridge@samba.org>
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/samba/netcmd/__init__.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py
index e5c5badb18..5e71a1c535 100644
--- a/source4/scripting/python/samba/netcmd/__init__.py
+++ b/source4/scripting/python/samba/netcmd/__init__.py
@@ -29,6 +29,7 @@ class Option(optparse.Option):
pass
+
class Command(object):
"""A net command."""
@@ -88,7 +89,6 @@ class Command(object):
if force_traceback or samba.get_debug_level() >= 3:
traceback.print_tb(etraceback)
-
synopsis = property(_get_synopsis)
outf = sys.stdout
@@ -146,6 +146,7 @@ class Command(object):
raise NotImplementedError(self.run)
+
class SuperCommand(Command):
"""A command with subcommands."""
@@ -159,7 +160,13 @@ class SuperCommand(Command):
print "\t%-20s - %s" % (cmd, self.subcommands[cmd].description)
if subcommand in [None, 'help', '-h', '--help' ]:
return 0
- raise CommandError("No such subcommand '%s'" % subcommand)
+ self.show_command_error("No such subcommand '%s'" % (subcommand))
+
+ def show_command_error(self, msg):
+ '''display a command error'''
+
+ print >>sys.stderr, "ERROR: %s" % (msg)
+ return -1
def usage(self, myname, subcommand=None, *args):
if subcommand is None or not subcommand in self.subcommands:
@@ -169,6 +176,7 @@ class SuperCommand(Command):
return self.subcommands[subcommand].usage(*args)
+
class CommandError(Exception):
'''an exception class for netcmd errors'''
def __init__(self, message, inner_exception=None):
@@ -177,6 +185,7 @@ class CommandError(Exception):
self.exception_info = sys.exc_info()
+
commands = {}
from samba.netcmd.newuser import cmd_newuser
commands["newuser"] = cmd_newuser()