diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2011-10-13 23:08:32 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2011-10-14 00:22:56 +0200 |
commit | be7a75b29a5481c8a4fd52cc1d7fb2d329f88898 (patch) | |
tree | 2bd38fd88329f13347a51bf63a9570d50809a1cb /source4 | |
parent | 60de9b7bbf991291baa361a48c63f3b47402c719 (diff) | |
download | samba-be7a75b29a5481c8a4fd52cc1d7fb2d329f88898.tar.gz samba-be7a75b29a5481c8a4fd52cc1d7fb2d329f88898.tar.bz2 samba-be7a75b29a5481c8a4fd52cc1d7fb2d329f88898.zip |
samba-tool: Determine long option from docstring.
Diffstat (limited to 'source4')
-rw-r--r-- | source4/scripting/python/samba/netcmd/__init__.py | 29 | ||||
-rw-r--r-- | source4/scripting/python/samba/netcmd/domain.py | 11 | ||||
-rwxr-xr-x | source4/scripting/python/samba/netcmd/testparm.py | 2 |
3 files changed, 25 insertions, 17 deletions
diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py index 33ed3d5578..19fae071c6 100644 --- a/source4/scripting/python/samba/netcmd/__init__.py +++ b/source4/scripting/python/samba/netcmd/__init__.py @@ -23,6 +23,7 @@ import optparse, samba from samba import getopt as options from ldb import LdbError import sys, traceback +import textwrap class Option(optparse.Option): @@ -32,16 +33,21 @@ class Option(optparse.Option): class Command(object): """A samba-tool command.""" - - def _get_description(self): + + def _get_short_description(self): return self.__doc__.splitlines()[0].rstrip("\n") - description = property(_get_description) + short_description = property(_get_short_description) + + def _get_full_description(self): + lines = self.__doc__.split("\n") + return lines[0] + "\n" + textwrap.dedent("\n".join(lines[1:])) - # synopsis must be defined in all subclasses in order to provide the command usage - synopsis = "Please provide synopsis for this command." - # long_description is a string describing the command in details - long_description = "" + full_description = property(_get_full_description) + + # synopsis must be defined in all subclasses in order to provide the + # command usage + synopsis = None takes_args = [] takes_options = [] takes_optiongroups = { @@ -91,7 +97,7 @@ class Command(object): def _create_parser(self): parser = optparse.OptionParser(usage=self.synopsis, - description=self.long_description) + description=self.full_description) parser.add_options(self.takes_options) optiongroups = {} for name, optiongroup in self.takes_optiongroups.iteritems(): @@ -157,8 +163,8 @@ class SuperCommand(Command): def _run(self, myname, subcommand=None, *args): if subcommand in self.subcommands: return self.subcommands[subcommand]._run(subcommand, *args) - - if (myname == "samba-tool"): + + if myname == "samba-tool": usage = "samba-tool <subcommand>" else: usage = "samba-tool %s <subcommand>" % myname @@ -168,7 +174,8 @@ class SuperCommand(Command): subcmds.sort() max_length = max([len(c) for c in subcmds]) for cmd in subcmds: - self.outf.write(" %*s - %s\n" % (-max_length, cmd, self.subcommands[cmd].description)) + self.outf.write(" %*s - %s\n" % ( + -max_length, cmd, self.subcommands[cmd].short_description)) if subcommand in [None]: raise CommandError("You must specify a subcommand") if subcommand in ['help', '-h', '--help']: diff --git a/source4/scripting/python/samba/netcmd/domain.py b/source4/scripting/python/samba/netcmd/domain.py index 05e82b5dfa..77026b9839 100644 --- a/source4/scripting/python/samba/netcmd/domain.py +++ b/source4/scripting/python/samba/netcmd/domain.py @@ -25,7 +25,7 @@ import samba.getopt as options import ldb -import sys, os +import os import tempfile import logging from samba import Ldb @@ -528,12 +528,13 @@ class cmd_domain_passwordsettings(Command): class cmd_domain_samba3upgrade(Command): - """Upgrade from Samba3 database to Samba4 AD database""" + """Upgrade from Samba3 database to Samba4 AD database. - synopsis = "%prog domain samba3upgrade [options] <samba3_smb_conf>" + Specify either samba3 database directory (with --libdir) or + samba3 testparm utility (with --testparm). + """ - long_description = """Specify either samba3 database directory (with --libdir) or -samba3 testparm utility (with --testparm).""" + synopsis = "%prog domain samba3upgrade [options] <samba3_smb_conf>" takes_optiongroups = { "sambaopts": options.SambaOptions, diff --git a/source4/scripting/python/samba/netcmd/testparm.py b/source4/scripting/python/samba/netcmd/testparm.py index 9de6fdfa20..b69c351538 100755 --- a/source4/scripting/python/samba/netcmd/testparm.py +++ b/source4/scripting/python/samba/netcmd/testparm.py @@ -42,7 +42,7 @@ import samba.getopt as options from samba.netcmd import Command, CommandError, Option class cmd_testparm(Command): - """Syntax check the configuration file""" + """Syntax check the configuration file.""" synopsis = "%prog testparm [options]" |