The branch, master has been updated
via 1b27efd samba-tool: Add test to make sure all commands have a short
description set.
via 37a4bcd samba-tool: Add test to make sure all commands have a
synopsis set.
via 9e1ef61 samba-tool: Move main command implementation to
samba.netcmd.main, so it is accessible by the testsuite.
via 9213f39 samba-tool: Don't require full prog line to be in synopsis.
via b5d5945 samba.netcmd: Reintroduce Command.name.
via 27afc3e CodingStyle: Add some notes about Python 2.4 compatibility.
via be7a75b samba-tool: Determine long option from docstring.
via 60de9b7 creds: Remove unnecessary calls to credopts.get_credentials.
via 36e3c15 python: Remove extra newlines.
from b0d89e5 s4:selftest: flakey test samba4.drs.delete_object.python
should go into skip
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 1b27efd9107eef290e2c7d4826953157bab2f3c4
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 23:49:05 2011 +0200
samba-tool: Add test to make sure all commands have a short description set.
Autobuild-User: Jelmer Vernooij <[email protected]>
Autobuild-Date: Fri Oct 14 01:53:45 CEST 2011 on sn-devel-104
commit 37a4bcd28b997eca2c3e5ba60b516b6662bbe6a4
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 23:47:45 2011 +0200
samba-tool: Add test to make sure all commands have a synopsis set.
commit 9e1ef61b34b7a4ec63d5bf58e50e64af16a24c43
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 23:36:10 2011 +0200
samba-tool: Move main command implementation to samba.netcmd.main, so it is
accessible by the testsuite.
commit 9213f398adf9aa29d0c59a4caee440dba70e4a7d
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 23:27:22 2011 +0200
samba-tool: Don't require full prog line to be in synopsis.
commit b5d59458012d1b9f91bd08f4c36fc108f23af19a
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 23:16:58 2011 +0200
samba.netcmd: Reintroduce Command.name.
commit 27afc3e578d38279085ad2984c8ff2f9e0484540
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 23:08:45 2011 +0200
CodingStyle: Add some notes about Python 2.4 compatibility.
commit be7a75b29a5481c8a4fd52cc1d7fb2d329f88898
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 23:08:32 2011 +0200
samba-tool: Determine long option from docstring.
commit 60de9b7bbf991291baa361a48c63f3b47402c719
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 22:24:50 2011 +0200
creds: Remove unnecessary calls to credopts.get_credentials.
commit 36e3c15f54f1afdde662e45f11ae4b819fbad504
Author: Jelmer Vernooij <[email protected]>
Date: Thu Oct 13 22:21:48 2011 +0200
python: Remove extra newlines.
-----------------------------------------------------------------------
Summary of changes:
README.Coding | 10 ++-
source4/scripting/bin/samba-tool | 78 +++++---------------
source4/scripting/python/samba/netcmd/__init__.py | 65 ++++++++++------
source4/scripting/python/samba/netcmd/common.py | 3 -
source4/scripting/python/samba/netcmd/dbcheck.py | 2 +-
.../scripting/python/samba/netcmd/delegation.py | 18 ++---
source4/scripting/python/samba/netcmd/domain.py | 21 +++---
source4/scripting/python/samba/netcmd/drs.py | 10 +-
source4/scripting/python/samba/netcmd/dsacl.py | 2 +-
source4/scripting/python/samba/netcmd/fsmo.py | 17 ++---
source4/scripting/python/samba/netcmd/gpo.py | 40 +++++-----
source4/scripting/python/samba/netcmd/group.py | 8 +-
source4/scripting/python/samba/netcmd/ldapcmp.py | 2 +-
.../samba-tool => python/samba/netcmd/main.py} | 33 +-------
source4/scripting/python/samba/netcmd/ntacl.py | 7 +-
source4/scripting/python/samba/netcmd/rodc.py | 4 +-
source4/scripting/python/samba/netcmd/spn.py | 10 +--
source4/scripting/python/samba/netcmd/testparm.py | 4 +-
source4/scripting/python/samba/netcmd/time.py | 2 +-
source4/scripting/python/samba/netcmd/user.py | 14 ++--
source4/scripting/python/samba/netcmd/vampire.py | 3 +-
source4/scripting/python/samba/tests/netcmd.py | 42 ++++++++++-
22 files changed, 182 insertions(+), 213 deletions(-)
copy source4/scripting/{bin/samba-tool => python/samba/netcmd/main.py} (73%)
mode change 100755 => 100644
Changeset truncated at 500 lines:
diff --git a/README.Coding b/README.Coding
index 12997cc..8416290 100644
--- a/README.Coding
+++ b/README.Coding
@@ -21,9 +21,13 @@ coding style (See Documentation/CodingStyle in the kernel
source tree). This
closely matches what most Samba developers use already anyways, with a few
exceptions as mentioned below.
-The coding style for Python code is documented in PEP8,
http://www.python.org/pep/pep8.
-If you have ever worked on another free software python project, you are
probably
-already familiar with it.
+The coding style for Python code is documented in PEP8,
+http://www.python.org/pep/pep8 (with spaces).
+If you have ever worked on another free software Python project, you are
+probably already familiar with it.
+
+We try to stay compatible with Python 2.4, so please don't rely on any
+features that were introduced later, such as the "with" statement.
But to save you the trouble of reading the Linux kernel style guide, here
are the highlights.
diff --git a/source4/scripting/bin/samba-tool b/source4/scripting/bin/samba-tool
index 9f06e8d..c4ea814 100755
--- a/source4/scripting/bin/samba-tool
+++ b/source4/scripting/bin/samba-tool
@@ -23,63 +23,21 @@ import sys
# Find right direction when running from source tree
sys.path.insert(0, "bin/python")
-from samba import netcmd
-from samba.netcmd import SuperCommand
-from samba.netcmd.dbcheck import cmd_dbcheck
-from samba.netcmd.delegation import cmd_delegation
-from samba.netcmd.domain import cmd_domain
-from samba.netcmd.drs import cmd_drs
-from samba.netcmd.dsacl import cmd_dsacl
-from samba.netcmd.fsmo import cmd_fsmo
-from samba.netcmd.gpo import cmd_gpo
-from samba.netcmd.group import cmd_group
-from samba.netcmd.ldapcmp import cmd_ldapcmp
-from samba.netcmd.ntacl import cmd_ntacl
-from samba.netcmd.rodc import cmd_rodc
-from samba.netcmd.spn import cmd_spn
-from samba.netcmd.testparm import cmd_testparm
-from samba.netcmd.time import cmd_time
-from samba.netcmd.user import cmd_user
-from samba.netcmd.vampire import cmd_vampire
-
-
-class cmd_sambatool(SuperCommand):
- """samba-tool SuperCommand"""
-
- subcommands = {}
- subcommands["dbcheck"] = cmd_dbcheck()
- subcommands["delegation"] = cmd_delegation()
- subcommands["domain"] = cmd_domain()
- subcommands["drs"] = cmd_drs()
- subcommands["dsacl"] = cmd_dsacl()
- subcommands["fsmo"] = cmd_fsmo()
- subcommands["gpo"] = cmd_gpo()
- subcommands["group"] = cmd_group()
- subcommands["ldapcmp"] = cmd_ldapcmp()
- subcommands["ntacl"] = cmd_ntacl()
- subcommands["rodc"] = cmd_rodc()
- subcommands["spn"] = cmd_spn()
- subcommands["testparm"] = cmd_testparm()
- subcommands["time"] = cmd_time()
- subcommands["user"] = cmd_user()
- subcommands["vampire"] = cmd_vampire()
-
-
-if __name__ == '__main__':
- cmd = cmd_sambatool()
- subcommand = None
- args = ()
-
- if len(sys.argv) > 1:
- subcommand = sys.argv[1]
- if len(sys.argv) > 2:
- args = sys.argv[2:]
-
- try:
- retval = cmd._run("samba-tool", subcommand, *args)
- except SystemExit, e:
- retval = -1
- except Exception, e:
- cmd.show_command_error(e)
- retval = 1
- sys.exit(retval)
+from samba.netcmd.main import cmd_sambatool
+cmd = cmd_sambatool()
+subcommand = None
+args = ()
+
+if len(sys.argv) > 1:
+ subcommand = sys.argv[1]
+ if len(sys.argv) > 2:
+ args = sys.argv[2:]
+
+try:
+ retval = cmd._run("samba-tool", subcommand, *args)
+except SystemExit, e:
+ retval = -1
+except Exception, e:
+ cmd.show_command_error(e)
+ retval = 1
+sys.exit(retval)
diff --git a/source4/scripting/python/samba/netcmd/__init__.py
b/source4/scripting/python/samba/netcmd/__init__.py
index 33ed3d5..bf08457 100644
--- a/source4/scripting/python/samba/netcmd/__init__.py
+++ b/source4/scripting/python/samba/netcmd/__init__.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Unix SMB/CIFS implementation.
-# Copyright (C) Jelmer Vernooij <[email protected]> 2009
+# Copyright (C) Jelmer Vernooij <[email protected]> 2009-2011
# Copyright (C) Theresa Halloran <[email protected]> 2011
# Copyright (C) Giampaolo Lauria <[email protected]> 2011
#
@@ -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,29 @@ 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:]))
+
+ full_description = property(_get_full_description)
+
+ def _get_name(self):
+ name = self.__class__.__name__
+ if name.startswith("cmd_"):
+ return name[4:]
+ return name
+
+ name = property(_get_name)
- # 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 = ""
+ # synopsis must be defined in all subclasses in order to provide the
+ # command usage
+ synopsis = None
takes_args = []
takes_options = []
takes_optiongroups = {
@@ -52,8 +66,8 @@ class Command(object):
outf = sys.stdout
errf = sys.stderr
- def usage(self, *args):
- parser, _ = self._create_parser()
+ def usage(self, prog, *args):
+ parser, _ = self._create_parser(prog)
parser.print_usage()
def show_command_error(self, e):
@@ -89,9 +103,11 @@ class Command(object):
if force_traceback or samba.get_debug_level() >= 3:
traceback.print_tb(etraceback)
- def _create_parser(self):
- parser = optparse.OptionParser(usage=self.synopsis,
- description=self.long_description)
+ def _create_parser(self, prog):
+ parser = optparse.OptionParser(
+ usage=self.synopsis,
+ description=self.full_description,
+ prog=prog)
parser.add_options(self.takes_options)
optiongroups = {}
for name, optiongroup in self.takes_optiongroups.iteritems():
@@ -103,7 +119,7 @@ class Command(object):
self.outf.write(text+"\n")
def _run(self, *argv):
- parser, optiongroups = self._create_parser()
+ parser, optiongroups = self._create_parser(argv[0])
opts, args = parser.parse_args(list(argv))
# Filter out options from option groups
args = args[1:]
@@ -152,34 +168,35 @@ class Command(object):
class SuperCommand(Command):
"""A samba-tool command with subcommands."""
+ synopsis = "%prog <subcommand>"
+
subcommands = {}
def _run(self, myname, subcommand=None, *args):
if subcommand in self.subcommands:
- return self.subcommands[subcommand]._run(subcommand, *args)
-
- if (myname == "samba-tool"):
- usage = "samba-tool <subcommand>"
- else:
- usage = "samba-tool %s <subcommand>" % myname
- self.outf.write("Usage: %s [options]\n" % usage)
+ return self.subcommands[subcommand]._run(
+ "%s %s" % (myname, subcommand), *args)
+
+ self.usage(myname)
self.outf.write("Available subcommands:\n")
subcmds = self.subcommands.keys()
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']:
- self.outf.write("For more help on a specific subcommand, please
type: %s (-h|--help)\n" % usage)
+ self.outf.write("For more help on a specific subcommand, please
type: %s (-h|--help)\n" % myname)
return 0
raise CommandError("No such subcommand '%s'" % subcommand)
class CommandError(Exception):
- '''an exception class for samba-tool cmd errors'''
+ """An exception class for samba-tool Command errors."""
+
def __init__(self, message, inner_exception=None):
self.message = message
self.inner_exception = inner_exception
diff --git a/source4/scripting/python/samba/netcmd/common.py
b/source4/scripting/python/samba/netcmd/common.py
index a4ebdd4..234fad3 100644
--- a/source4/scripting/python/samba/netcmd/common.py
+++ b/source4/scripting/python/samba/netcmd/common.py
@@ -24,7 +24,6 @@ from samba.dcerpc import nbt
from samba.net import Net
-
def _get_user_realm_domain(user):
""" get the realm or the domain and the base user
from user like:
@@ -47,14 +46,12 @@ def _get_user_realm_domain(user):
return (baseuser.lower(), domain, realm.upper())
-
def netcmd_dnsname(lp):
'''return the full DNS name of our own host. Used as a default
for hostname when running status queries'''
return lp.get('netbios name').lower() + "." + lp.get('realm').lower()
-
def netcmd_finddc(lp, creds):
'''return domain-name of a writable/ldap-capable DC for the domain.'''
net = Net(creds=creds, lp=lp)
diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py
b/source4/scripting/python/samba/netcmd/dbcheck.py
index 44f3ded..1d4a5b4 100644
--- a/source4/scripting/python/samba/netcmd/dbcheck.py
+++ b/source4/scripting/python/samba/netcmd/dbcheck.py
@@ -33,7 +33,7 @@ from samba.dbchecker import dbcheck
class cmd_dbcheck(Command):
"""check local AD database for errors"""
- synopsis = "%prog dbcheck [<DN>] [options]"
+ synopsis = "%prog [<DN>] [options]"
takes_args = ["DN?"]
diff --git a/source4/scripting/python/samba/netcmd/delegation.py
b/source4/scripting/python/samba/netcmd/delegation.py
index 24f4f51..0aed394 100644
--- a/source4/scripting/python/samba/netcmd/delegation.py
+++ b/source4/scripting/python/samba/netcmd/delegation.py
@@ -36,11 +36,10 @@ from samba.netcmd import (
)
-
class cmd_delegation_show(Command):
"""Show the delegation setting of an account."""
-
- synopsis = "%prog delegation show <accountname> [options]"
+
+ synopsis = "%prog show <accountname> [options]"
takes_args = ["accountname"]
@@ -74,11 +73,10 @@ class cmd_delegation_show(Command):
self.outf.write("msDS-AllowedToDelegateTo: %s\n" % a)
-
class cmd_delegation_for_any_service(Command):
"""Set/unset UF_TRUSTED_FOR_DELEGATION for an account."""
- synopsis = "%prog delegation for-any-service <accountname> [(on|off)]
[options]"
+ synopsis = "%prog <accountname> [(on|off)] [options]"
takes_args = ["accountname", "onoff"]
@@ -109,11 +107,10 @@ class cmd_delegation_for_any_service(Command):
raise CommandError(err)
-
class cmd_delegation_for_any_protocol(Command):
"""Set/unset UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION (S4U2Proxy) for an
account."""
- synopsis = "%prog delegation for-any-protocol <accountname> [(on|off)]
[options]"
+ synopsis = "%prog <accountname> [(on|off)] [options]"
takes_args = ["accountname", "onoff"]
@@ -144,11 +141,10 @@ class cmd_delegation_for_any_protocol(Command):
raise CommandError(err)
-
class cmd_delegation_add_service(Command):
"""Add a service principal as msDS-AllowedToDelegateTo"""
- synopsis = "%prog delegation add-service <accountname> <principal>
[options]"
+ synopsis = "%prog <accountname> <principal> [options]"
takes_args = ["accountname", "principal"]
@@ -180,11 +176,10 @@ class cmd_delegation_add_service(Command):
raise CommandError(err)
-
class cmd_delegation_del_service(Command):
"""Delete a service principal as msDS-AllowedToDelegateTo"""
- synopsis = "%prog delegation del-service <accountname> <principal>
[options]"
+ synopsis = "%prog <accountname> <principal> [options]"
takes_args = ["accountname", "principal"]
@@ -216,7 +211,6 @@ class cmd_delegation_del_service(Command):
raise CommandError(err)
-
class cmd_delegation(SuperCommand):
"""Delegation management"""
diff --git a/source4/scripting/python/samba/netcmd/domain.py
b/source4/scripting/python/samba/netcmd/domain.py
index 05e82b5..ce9d7d8 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
@@ -62,7 +62,7 @@ def get_testparm_var(testparm, smbconf, varname):
class cmd_domain_export_keytab(Command):
"""Dumps kerberos keys of the domain into a keytab"""
- synopsis = "%prog domain exportkeytab <keytab> [options]"
+ synopsis = "%prog <keytab> [options]"
takes_options = [
]
@@ -79,7 +79,7 @@ class cmd_domain_export_keytab(Command):
class cmd_domain_join(Command):
"""Joins domain as either member or backup domain controller *"""
- synopsis = "%prog domain join <dnsdomain> [DC|RODC|MEMBER|SUBDOMAIN]
[options]"
+ synopsis = "%prog <dnsdomain> [DC|RODC|MEMBER|SUBDOMAIN] [options]"
takes_options = [
Option("--server", help="DC to join", type=str),
@@ -140,7 +140,7 @@ class cmd_domain_join(Command):
class cmd_domain_level(Command):
"""Raises domain and forest function levels"""
- synopsis = "%prog domain level (show|raise <options>) [options]"
+ synopsis = "%prog (show|raise <options>) [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server",
type=str,
@@ -339,7 +339,7 @@ class cmd_domain_level(Command):
class cmd_domain_machinepassword(Command):
"""Gets a machine password out of our SAM"""
- synopsis = "%prog domain machinepassword <accountname> [options]"
+ synopsis = "%prog <accountname> [options]"
takes_args = ["secret"]
@@ -370,7 +370,7 @@ class cmd_domain_passwordsettings(Command):
and maximum password age) on a Samba4 server.
"""
- synopsis = "%prog domain passwordsettings (show|set <options>) [options]"
+ synopsis = "%prog (show|set <options>) [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server",
type=str,
@@ -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 [options] <samba3_smb_conf>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
diff --git a/source4/scripting/python/samba/netcmd/drs.py
b/source4/scripting/python/samba/netcmd/drs.py
index 78b998e..2f0e306 100644
--- a/source4/scripting/python/samba/netcmd/drs.py
+++ b/source4/scripting/python/samba/netcmd/drs.py
@@ -101,7 +101,7 @@ def get_dsServiceName(samdb):
class cmd_drs_showrepl(Command):
"""show replication status"""
- synopsis = "%prog drs showrepl [<DC>] [options]"
+ synopsis = "%prog [<DC>] [options]"
takes_args = ["DC?"]
@@ -206,7 +206,7 @@ class cmd_drs_showrepl(Command):
class cmd_drs_kcc(Command):
"""trigger knowledge consistency center run"""
- synopsis = "%prog drs kcc [<DC>] [options]"
+ synopsis = "%prog [<DC>] [options]"
takes_args = ["DC?"]
@@ -269,7 +269,7 @@ def drs_local_replicate(self, SOURCE_DC, NC):
class cmd_drs_replicate(Command):
"""replicate a naming context between two DCs"""
- synopsis = "%prog drs replicate <destinationDC> <sourceDC> <NC> [options]"
+ synopsis = "%prog <destinationDC> <sourceDC> <NC> [options]"
takes_args = ["DEST_DC", "SOURCE_DC", "NC"]
@@ -344,7 +344,7 @@ class cmd_drs_replicate(Command):
class cmd_drs_bind(Command):
"""show DRS capabilities of a server"""
- synopsis = "%prog drs bind [<DC>] [options]"
+ synopsis = "%prog [<DC>] [options]"
takes_args = ["DC?"]
@@ -437,7 +437,7 @@ class cmd_drs_bind(Command):
class cmd_drs_options(Command):
"""query or change 'options' for NTDS Settings object of a domain
controller"""
- synopsis = ("%prog drs options [<DC>] [options]")
+ synopsis = "%prog [<DC>] [options]"
takes_args = ["DC?"]
diff --git a/source4/scripting/python/samba/netcmd/dsacl.py
b/source4/scripting/python/samba/netcmd/dsacl.py
index 97d4eb8..b68af9b 100644
--- a/source4/scripting/python/samba/netcmd/dsacl.py
+++ b/source4/scripting/python/samba/netcmd/dsacl.py
@@ -50,7 +50,7 @@ from samba.netcmd import (
class cmd_dsacl_set(Command):
"""Modify access list on a directory object"""
- synopsis = "%prog dsacl set [options]"
+ synopsis = "%prog [options]"
car_help = """ The access control right to allow or deny """
--
Samba Shared Repository