1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

python: Add convenience function for getting command line loadparm context

and default to using system smb.conf.
(This used to be commit b3afde0f00)
This commit is contained in:
Jelmer Vernooij 2008-01-23 23:33:36 +01:00
parent 00cb710fbc
commit decdf5954d
6 changed files with 35 additions and 22 deletions

View File

@ -19,7 +19,8 @@ from samba import Ldb
import param
parser = optparse.OptionParser("ldap [options] <host>")
parser.add_option_group(options.SambaOptions(parser))
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
parser.add_option_group(options.VersionOptions(parser))
# use command line creds if available
credopts = options.CredentialsOptions(parser)
@ -33,9 +34,7 @@ if len(args) < 1:
host = args[0]
lp = param.LoadParm()
if opts.configfile:
lp.load(opts.configfile)
lp = sambaopts.get_loadparm()
def delete_force(ldb, dn):
try:

View File

@ -12,7 +12,8 @@ import optparse
import samba.getopt as options
parser = optparse.OptionParser("%s <BINDING> [path]" % sys.argv[0])
parser.add_option_group(options.SambaOptions(parser))
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
parser.add_option("--createkey", type="string", metavar="KEYNAME",
help="create a key")
@ -25,7 +26,7 @@ if len(args) < 1:
binding = args[0]
print "Connecting to " + binding
conn = winreg.winreg(binding, opts.configfile)
conn = winreg.winreg(binding, sambaopts.get_loadparm())
def list_values(key):
(num_values, max_valnamelen, max_valbufsize) = conn.QueryInfoKey(key, winreg.String())[4:8]

View File

@ -23,9 +23,25 @@ from credentials import Credentials
class SambaOptions(optparse.OptionGroup):
def __init__(self, parser):
optparse.OptionGroup.__init__(self, parser, "Samba Common Options")
self.add_option("-s", "--configfile", type="string", metavar="FILE",
help="Configuration file")
self.add_option("-s", "--configfile", action="callback",
type=str, metavar="FILE", help="Configuration file",
callback=self._load_configfile)
self._configfile = None
def get_loadparm_path(self):
return self._configfile
def _load_configfile(self, option, opt_str, arg, parser):
self._configfile = arg
def get_loadparm(self):
import param
lp = param.LoadParm()
if self._configfile is None:
lp.load_default()
else:
lp.load(self._configfile)
return lp
class VersionOptions(optparse.OptionGroup):
def __init__(self, parser):

View File

@ -37,7 +37,8 @@ from samba.provision import (provision,
provision_paths_from_lp)
parser = optparse.OptionParser("provision [options]")
parser.add_option_group(options.SambaOptions(parser))
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
parser.add_option_group(options.VersionOptions(parser))
credopts = options.CredentialsOptions(parser)
parser.add_option_group(credopts)
@ -111,9 +112,7 @@ if opts.realm is None or opts.domain is None:
sys.exit(1)
# cope with an initially blank smb.conf
lp = param.LoadParm()
if opts.configfile:
lp.load(opts.configfile)
lp = sambaopts.get_loadparm()
if opts.targetdir is not None:
if not os.path.exists(opts.targetdir):
os.mkdir(opts.targetdir)
@ -127,7 +126,7 @@ if opts.aci is not None:
print "set ACI: %s" % opts.aci
paths = provision_paths_from_lp(lp, opts.realm.lower())
paths.smbconf = opts.configfile
paths.smbconf = sambaopts.get_loadparm_path()
if opts.ldap_backend:
if opts.ldap_backend == "ldapi":

View File

@ -14,7 +14,8 @@ import samba.getopt as options
from auth import system_session
parser = optparse.OptionParser("upgrade [options] <libdir> <smbconf>")
parser.add_option_group(options.SambaOptions(parser))
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
parser.add_option_group(options.VersionOptions(parser))
credopts = options.CredentialsOptions(parser)
parser.add_option_group(credopts)
@ -59,15 +60,13 @@ if setup_dir is None:
setup_dir = "setup"
creds = credopts.get_credentials()
lp = param.LoadParm()
if opts.configfile:
lp.load(opts.configfile)
lp = sambaopts.get_loadparm()
if opts.targetdir is not None:
if not os.path.exists(opts.targetdir):
os.mkdir(opts.targetdir)
lp.set("private dir", os.path.abspath(opts.targetdir))
lp.set("lock dir", os.path.abspath(opts.targetdir))
paths = provision_paths_from_lp(lp, "")
paths.smbconf = opts.configfile
paths.smbconf = sambaopts.get_loadparm_path()
upgrade_provision(samba3, setup_dir, message, credentials=creds, session_info=system_session(),
lp=lp, paths=paths)

View File

@ -26,7 +26,8 @@ from auth import system_session
import sys
parser = optparse.OptionParser("vampire [options] <domain>")
parser.add_option_group(options.SambaOptions(parser))
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
parser.add_option_group(options.VersionOptions(parser))
credopts = options.CredentialsOptions(parser)
parser.add_option_group(credopts)
@ -47,8 +48,6 @@ def vampire(domain, session_info, credentials, lp):
ctx.samsync_ldb(vampire_ctx, machine_creds=machine_creds,
session_info=session_info)
lp = param.LoadParm()
if opts.configfile:
lp.load(opts.configfile)
lp = sambaopts.get_loadparm()
vampire(args[0], session_info=system_session(),
credentials=credopts.get_credentials(), lp=lp)