summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting')
-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()