from samba import getopt as options
from ldb import LdbError
import sys, traceback
+import textwrap
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 = {
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():
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
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']:
import samba.getopt as options
import ldb
-import sys, os
+import os
import tempfile
import logging
from samba import Ldb
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,