The branch, master has been updated via 8746faf s4:scripting/python: add '-V' as alias for '--version' via 309434a s4:samba-tool: allow 'samba-tool --version' via 2fce71c s4:samba-tool: use normal option parsing in SuperCommand via 8d4943d s4:samba-tool: add optional epilog to _create_parser() from c12cc3c s3fs-printing: Fix RAW printing for normal users.
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 8746faf846fb4f4552e648f4e4e05510b8bd1ef4 Author: Stefan Metzmacher <me...@samba.org> Date: Mon Oct 8 12:50:52 2012 +0200 s4:scripting/python: add '-V' as alias for '--version' metze Autobuild-User(master): Stefan Metzmacher <me...@samba.org> Autobuild-Date(master): Mon Oct 8 17:52:52 CEST 2012 on sn-devel-104 commit 309434a77396680b5a40985157da44aaddb5ca71 Author: Stefan Metzmacher <me...@samba.org> Date: Mon Oct 8 12:50:33 2012 +0200 s4:samba-tool: allow 'samba-tool --version' metze commit 2fce71c89af66c1467f0a18b97e237b307387620 Author: Stefan Metzmacher <me...@samba.org> Date: Mon Oct 8 12:47:47 2012 +0200 s4:samba-tool: use normal option parsing in SuperCommand We use the epilog to print the subcommands. metze commit 8d4943dcf943dc83b9b663d3d025fb1a8dbcba86 Author: Stefan Metzmacher <me...@samba.org> Date: Mon Oct 8 12:45:20 2012 +0200 s4:samba-tool: add optional epilog to _create_parser() metze ----------------------------------------------------------------------- Summary of changes: source4/scripting/python/samba/getopt.py | 2 +- source4/scripting/python/samba/netcmd/__init__.py | 32 +++++++++++++-------- source4/scripting/python/samba/netcmd/main.py | 6 ++++ 3 files changed, 27 insertions(+), 13 deletions(-) Changeset truncated at 500 lines: diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py index 1818ff3..c3c0800 100644 --- a/source4/scripting/python/samba/getopt.py +++ b/source4/scripting/python/samba/getopt.py @@ -100,7 +100,7 @@ class VersionOptions(optparse.OptionGroup): """Command line option for printing Samba version.""" def __init__(self, parser): optparse.OptionGroup.__init__(self, parser, "Version Options") - self.add_option("--version", action="callback", + self.add_option("-V", "--version", action="callback", callback=self._display_version, help="Display version number") diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py index ec2d222..a3edf50 100644 --- a/source4/scripting/python/samba/netcmd/__init__.py +++ b/source4/scripting/python/samba/netcmd/__init__.py @@ -40,6 +40,11 @@ class PlainHelpFormatter(optparse.IndentedHelpFormatter): result = "\n".join(wrapped_paragraphs) + "\n" return result + def format_epilog(self, epilog): + if epilog: + return "\n" + epilog + "\n" + else: + return "" class Command(object): """A samba-tool command.""" @@ -117,12 +122,12 @@ class Command(object): if force_traceback or samba.get_debug_level() >= 3: traceback.print_tb(etraceback) - def _create_parser(self, prog): + def _create_parser(self, prog, epilog=None): parser = optparse.OptionParser( usage=self.synopsis, description=self.full_description, formatter=PlainHelpFormatter(), - prog=prog) + prog=prog,epilog=epilog) parser.add_options(self.takes_options) optiongroups = {} for name, optiongroup in self.takes_optiongroups.iteritems(): @@ -196,22 +201,25 @@ class SuperCommand(Command): return self.subcommands[subcommand]._run( "%s %s" % (myname, subcommand), *args) - self.usage(myname) - self.outf.write("Available subcommands:\n") + epilog = "\nAvailable subcommands:\n" subcmds = self.subcommands.keys() subcmds.sort() max_length = max([len(c) for c in subcmds]) for cmd_name in subcmds: cmd = self.subcommands[cmd_name] if not cmd.hidden: - self.outf.write(" %*s - %s\n" % ( - -max_length, cmd_name, cmd.short_description)) - if subcommand in [None]: - raise CommandError("You must specify a subcommand") - if subcommand in ['help', '-h', '--help']: - self.outf.write("For more help on a specific subcommand, please type: %s <subcommand> (-h|--help)\n" % myname) - return 0 - raise CommandError("No such subcommand '%s'" % subcommand) + epilog += " %*s - %s\n" % ( + -max_length, cmd_name, cmd.short_description) + epilog += "For more help on a specific subcommand, please type: %s <subcommand> (-h|--help)\n" % myname + + parser, optiongroups = self._create_parser(myname, epilog=epilog) + args_list = list(args) + if subcommand: + args_list.insert(0, subcommand) + opts, args = parser.parse_args(args_list) + + parser.print_help() + return -1 class CommandError(Exception): diff --git a/source4/scripting/python/samba/netcmd/main.py b/source4/scripting/python/samba/netcmd/main.py index 5ffeef0..af3abfd 100644 --- a/source4/scripting/python/samba/netcmd/main.py +++ b/source4/scripting/python/samba/netcmd/main.py @@ -17,6 +17,8 @@ """The main samba-tool command implementation.""" +from samba import getopt as options + from samba.netcmd import SuperCommand from samba.netcmd.dbcheck import cmd_dbcheck from samba.netcmd.delegation import cmd_delegation @@ -41,6 +43,10 @@ from samba.netcmd.vampire import cmd_vampire class cmd_sambatool(SuperCommand): """Main samba administration tool.""" + takes_optiongroups = { + "versionopts": options.VersionOptions, + } + subcommands = {} subcommands["dbcheck"] = cmd_dbcheck() subcommands["delegation"] = cmd_delegation() -- Samba Shared Repository