diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2009-12-30 21:06:21 +0100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2009-12-31 17:33:28 +1100 |
commit | 7effe2d2e30191c067ae1290224d388d96701b53 (patch) | |
tree | ecdd3ab444261dd81548b3afd9dd4099812b6ae1 /source4/scripting/python | |
parent | 9e5ef916d41ee5f27616d18e431a9943310d3db6 (diff) | |
download | samba-7effe2d2e30191c067ae1290224d388d96701b53.tar.gz samba-7effe2d2e30191c067ae1290224d388d96701b53.tar.bz2 samba-7effe2d2e30191c067ae1290224d388d96701b53.zip |
net: Support 'super' commands implemented in Python.
Signed-off-by: Andrew Tridgell <tridge@samba.org>
Diffstat (limited to 'source4/scripting/python')
-rw-r--r-- | source4/scripting/python/samba/netcmd/__init__.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py index 9798f3529b..a204ab897b 100644 --- a/source4/scripting/python/samba/netcmd/__init__.py +++ b/source4/scripting/python/samba/netcmd/__init__.py @@ -40,7 +40,7 @@ class Command(object): name = property(_get_name) - def usage(self, args): + def usage(self, *args): parser, _ = self._create_parser() parser.print_usage() @@ -49,7 +49,7 @@ class Command(object): def _get_synopsis(self): ret = self.name if self.takes_args: - ret += " " + " ".join(self.takes_args) + ret += " " + " ".join([x.upper() for x in self.takes_args]) return ret synopsis = property(_get_synopsis) @@ -90,7 +90,7 @@ class Command(object): if arg[-1] == "*": max_args = -1 if len(args) < min_args or (max_args != -1 and len(args) > max_args): - self.usage(args) + self.usage(*args) return -1 try: return self.run(*args, **kwargs) @@ -108,21 +108,22 @@ class SuperCommand(Command): subcommands = {} - def run(self, subcommand, *args, **kwargs): - if not subcommand in subcommands: - print >>sys.stderr, "ERROR: No such subcommand '%s'" % subcommand - return subcommands[subcommand].run(*args, **kwargs) - - def usage(self, subcommand=None, *args, **kwargs): + def _run(self, myname, subcommand=None, *args): if subcommand is None: - print "Available subcommands" - for subcommand in subcommands: + print "Available subcommands:" + for subcommand in self.subcommands: print "\t%s" % subcommand return 0 + if not subcommand in self.subcommands: + raise CommandError("No such subcommand '%s'" % subcommand) + return self.subcommands[subcommand]._run(subcommand, *args) + + def usage(self, myname, subcommand=None, *args): + if subcommand is None or not subcommand in self.subcommands: + print "Usage: %s (%s) [options]" % (myname, + " | ".join(self.subcommands.keys())) else: - if not subcommand in subcommands: - print >>sys.stderr, "ERROR: No such subcommand '%s'" % subcommand - return subcommands[subcommand].usage(*args, **kwargs) + return self.subcommands[subcommand].usage(*args) class CommandError(Exception): |