1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-08 04:58:40 +03:00

samba-tool: moved takes_optiongroups definition to Command base class

The option groups should be defined at the Command base class level as they are in common across all samba-tool commands.
Major move advantages:
1. more OOP approach
2. enforcing consistency across commands
3. avoiding the need of declaring for every new command

Signed-off-by: Andrew Tridgell <tridge@samba.org>
This commit is contained in:
Giampaolo Lauria 2011-07-15 12:07:03 -04:00 committed by Andrew Tridgell
parent 1dfcb019d2
commit f6fa868489
19 changed files with 23 additions and 240 deletions

View File

@ -3,6 +3,7 @@
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
# Copyright (C) Theresa Halloran <theresahalloran@gmail.com> 2011
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -94,7 +95,11 @@ class Command(object):
takes_args = []
takes_options = []
takes_optiongroups = {}
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
def _create_parser(self):
parser = optparse.OptionParser(self.synopsis)

View File

@ -3,6 +3,7 @@
# Samba4 AD database checker
#
# Copyright (C) Andrew Tridgell 2011
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -34,12 +35,6 @@ class cmd_dbcheck(Command):
"""check local AD database for errors"""
synopsis = "dbcheck <DN> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptionsDouble,
}
takes_args = ["DN?"]
takes_options = [

View File

@ -5,6 +5,7 @@
# Copyright Matthieu Patou mat@samba.org 2010
# Copyright Stefan Metzmacher metze@samba.org 2011
# Copyright Bjoern Baumbach bb@sernet.de 2011
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -59,12 +60,6 @@ class cmd_delegation_show(Command):
"""Show the delegation setting of an account."""
synopsis = "%prog delegation show <accountname>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["accountname"]
def run(self, accountname, credopts=None, sambaopts=None, versionopts=None):
@ -106,12 +101,6 @@ 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"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["accountname", "onoff"]
def run(self, accountname, onoff, credopts=None, sambaopts=None, versionopts=None):
@ -144,12 +133,6 @@ 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"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["accountname", "onoff"]
def run(self, accountname, onoff, credopts=None, sambaopts=None, versionopts=None):
@ -182,12 +165,6 @@ class cmd_delegation_add_service(Command):
"""Add a service principal as msDS-AllowedToDelegateTo"""
synopsis = "%prog delegation add-service <accountname> <principal>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["accountname", "principal"]
def run(self, accountname, principal, credopts=None, sambaopts=None, versionopts=None):
@ -221,12 +198,6 @@ class cmd_delegation_del_service(Command):
"""Add a service principal as msDS-AllowedToDelegateTo"""
synopsis = "%prog delegation del-service <accountname> <principal>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["accountname", "principal"]
def run(self, accountname, principal, credopts=None, sambaopts=None, versionopts=None):

View File

@ -54,12 +54,6 @@ class cmd_domain_dumpkeys(Command):
"""Dumps kerberos keys of the domain into a keytab"""
synopsis = "%prog domain dumpkeys <keytab>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
]
@ -77,12 +71,6 @@ class cmd_domain_join(Command):
synopsis = "%prog domain join <dnsdomain> [DC | RODC | MEMBER] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("--server", help="DC to join", type=str),
Option("--site", help="site to join", type=str),
@ -130,12 +118,6 @@ class cmd_domain_level(Command):
synopsis = "%prog domain level (show | raise <options>)"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--quiet", help="Be quiet", action="store_true"),
@ -321,12 +303,6 @@ class cmd_domain_machinepassword(Command):
synopsis = "%prog domain machinepassword <accountname>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["secret"]
def run(self, secret, sambaopts=None, credopts=None, versionopts=None):
@ -358,12 +334,6 @@ class cmd_domain_passwordsettings(Command):
synopsis = "%prog domain passwordsettings (show | set <options>)"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--quiet", help="Be quiet", action="store_true"),

View File

@ -3,6 +3,7 @@
# implement samba_tool drs commands
#
# Copyright Andrew Tridgell 2010
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# based on C implementation by Kamen Mazdrashki <kamen.mazdrashki@postpath.com>
#
@ -94,12 +95,6 @@ class cmd_drs_showrepl(Command):
synopsis = "%prog drs showrepl <DC>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DC?"]
def print_neighbour(self, n):
@ -205,12 +200,6 @@ class cmd_drs_kcc(Command):
synopsis = "%prog drs kcc <DC>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DC?"]
def run(self, DC=None, sambaopts=None,
@ -272,12 +261,6 @@ class cmd_drs_replicate(Command):
synopsis = "%prog drs replicate <DEST_DC> <SOURCE_DC> <NC>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DEST_DC", "SOURCE_DC", "NC"]
takes_options = [
@ -346,12 +329,6 @@ class cmd_drs_bind(Command):
synopsis = "%prog drs bind <DC>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DC?"]
def run(self, DC=None, sambaopts=None,
@ -447,12 +424,6 @@ class cmd_drs_options(Command):
" [--dsa-option={+|-}IS_GC | {+|-}DISABLE_INBOUND_REPL"
" |{+|-}DISABLE_OUTBOUND_REPL | {+|-}DISABLE_NTDSCONN_XLATE]")
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DC?"]
takes_options = [

View File

@ -3,6 +3,7 @@
# Manipulate ACLs on directory objects
#
# Copyright (C) Nadezhda Ivanova <nivanova@samba.org> 2010
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -50,12 +51,6 @@ class cmd_ds_acl_set(Command):
synopsis = "set --objectdn=objectdn --car=control right --action=[deny|allow] --trusteedn=trustee-dn"
car_help = """ The access control right to allow or deny """
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("--host", help="LDB URL for database or target server",
type=str),

View File

@ -4,6 +4,7 @@
#
# Copyright Nadezhda Ivanova 2009
# Copyright Jelmer Vernooij 2009
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -36,12 +37,6 @@ class cmd_fsmo(Command):
synopsis = "(show | transfer <options> | seize <options>)"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("--url", help="LDB URL for database or target server", type=str),
Option("--force", help="Force seizing of the role without attempting to transfer first.", action="store_true"),

View File

@ -3,6 +3,7 @@
# implement samba_tool gpo commands
#
# Copyright Andrew Tridgell 2010
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# based on C implementation by Guenther Deschner and Wilco Baan Hofman
#
@ -88,12 +89,6 @@ class cmd_listall(Command):
synopsis = "%prog gpo listall"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str)
]
@ -136,12 +131,6 @@ class cmd_list(Command):
synopsis = "%prog gpo list <username>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = [ 'username' ]
takes_options = [

View File

@ -5,6 +5,7 @@
#
# Based on the original in EJS:
# Copyright Andrew Tridgell 2005
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -44,12 +45,6 @@ class cmd_group_add(Command):
synopsis = "%prog group add [options] <groupname>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--groupou",
@ -93,12 +88,6 @@ class cmd_group_delete(Command):
synopsis = "%prog group delete <groupname>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
]
@ -124,12 +113,6 @@ class cmd_group_add_members(Command):
synopsis = "%prog group addmembers <groupname> <listofmembers>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
]
@ -156,12 +139,6 @@ class cmd_group_remove_members(Command):
synopsis = "%prog group removemembers <groupname> <listofmembers>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
]

View File

@ -8,6 +8,7 @@
# above partitions.
# Copyright (C) Zahari Zahariev <zahari.zahariev@postpath.com> 2009, 2010
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -841,12 +842,6 @@ class cmd_ldapcmp(Command):
"""compare two ldap databases"""
synopsis = "ldapcmp URL1 URL2 <domain|configuration|schema> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptionsDouble,
}
takes_args = ["URL1", "URL2", "context1?", "context2?", "context3?"]
takes_options = [

View File

@ -4,6 +4,7 @@
#
# Copyright (C) Matthieu Patou <mat@matws.net> 2010
# Copyright (C) Nadezhda Ivanova <nivanova@samba.org> 2010
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@ -5,6 +5,7 @@
#
# Based on the original in EJS:
# Copyright Andrew Tridgell 2005
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -32,12 +33,6 @@ class cmd_newuser(Command):
synopsis = "newuser [options] <username> [<password>]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--must-change-at-next-login",

View File

@ -3,6 +3,7 @@
# Manipulate file NT ACLs
#
# Copyright Matthieu Patou 2010 <mat@matws.net>
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -40,12 +41,6 @@ class cmd_acl_set(Command):
"""Set ACLs on a file"""
synopsis = "%prog set <acl> <file> [--xattr-backend=native|tdb] [--eadb-file=file] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("--quiet", help="Be quiet", action="store_true"),
Option("--xattr-backend", type="choice", help="xattr backend type (native fs or tdb)",
@ -83,12 +78,6 @@ class cmd_acl_get(Command):
"""Set ACLs on a file"""
synopsis = "%prog get <file> [--as-sddl] [--xattr-backend=native|tdb] [--eadb-file=file] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("--as-sddl", help="Output ACL in the SDDL format", action="store_true"),
Option("--xattr-backend", type="choice", help="xattr backend type (native fs or tdb)",

View File

@ -3,6 +3,7 @@
# rodc related commands
#
# Copyright Andrew Tridgell 2010
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -32,12 +33,6 @@ class cmd_rodc_preload(Command):
synopsis = "%prog rodc preload <SID|DN|accountname>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("--server", help="DC to use", type=str),
]

View File

@ -3,6 +3,7 @@
# spn management
#
# Copyright Matthieu Patou mat@samba.org 2010
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -56,12 +57,6 @@ class cmd_spn_list(Command):
"""List spns of a given user."""
synopsis = "%prog spn list <user>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["user"]
def run(self, user, credopts=None, sambaopts=None, versionopts=None):
@ -95,11 +90,6 @@ class cmd_spn_add(Command):
"""Create a new spn."""
synopsis = "%prog spn add [--force] <name> <user>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("--force", help="Force the addition of the spn"\
" even it exists already", action="store_true"),
@ -153,12 +143,6 @@ class cmd_spn_delete(Command):
"""Delete a spn."""
synopsis = "%prog spn delete <name> [user]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["name", "user?"]
def run(self, name, user=None, credopts=None, sambaopts=None, versionopts=None):

View File

@ -4,6 +4,7 @@
# Unix SMB/CIFS implementation.
# Test validity of smb.conf
# Copyright (C) Karl Auer 1993, 1994-1998
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# Extensively modified by Andrew Tridgell, 1995
# Converted to popt by Jelmer Vernooij (jelmer@nl.linux.org), 2002
@ -45,11 +46,6 @@ class cmd_testparm(Command):
synopsis = ""
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions
}
takes_options = [
Option("--section-name", type=str,
help="Limit testparm to a named section"),

View File

@ -3,6 +3,7 @@
# time
#
# Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -30,12 +31,6 @@ class cmd_time(Command):
"""Retrieve the time on a remote server [server connection needed]"""
synopsis = "%prog time <server-name>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["server_name?"]
def run(self, server_name=None, credopts=None, sambaopts=None, versionopts=None):

View File

@ -4,6 +4,7 @@
#
# Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
# Copyright Theresa Halloran 2011 <theresahalloran@gmail.com>
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -39,12 +40,6 @@ class cmd_user_add(Command):
"""Create a new user."""
synopsis = "%prog user add <name> [<password>]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["name", "password?"]
def run(self, name, password=None, credopts=None, sambaopts=None, versionopts=None):
@ -60,12 +55,6 @@ class cmd_user_delete(Command):
"""Delete a user."""
synopsis = "%prog user delete <name>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["name"]
def run(self, name, credopts=None, sambaopts=None, versionopts=None):
@ -83,13 +72,6 @@ class cmd_user_enable(Command):
synopsis = "%prog user enable <username> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--filter", help="LDAP Filter to set password on", type=str),
@ -122,12 +104,6 @@ class cmd_user_setexpiry(Command):
synopsis = "%prog user setexpiry <username> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--filter", help="LDAP Filter to set password on", type=str),
@ -165,12 +141,6 @@ class cmd_user_setpassword(Command):
synopsis = "%prog user setpassword [username] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--filter", help="LDAP Filter to set password on", type=str),

View File

@ -3,6 +3,7 @@
# Vampire
#
# Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -33,12 +34,6 @@ class cmd_vampire(Command):
"""Join and synchronise a remote AD domain to the local server [server connection needed]"""
synopsis = "%prog vampire [options] <domain>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("--target-dir", help="Target directory.", type=str),
Option("--force", help="force run", action='store_true', default=False),