summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsource4/lib/ldb/tests/python/ldap.py7
-rwxr-xr-xsource4/scripting/bin/winreg.py5
-rw-r--r--source4/scripting/python/samba/getopt.py20
-rwxr-xr-xsource4/setup/provision.py9
-rwxr-xr-xsource4/setup/upgrade.py9
-rwxr-xr-xsource4/setup/vampire.py7
6 files changed, 35 insertions, 22 deletions
diff --git a/source4/lib/ldb/tests/python/ldap.py b/source4/lib/ldb/tests/python/ldap.py
index 01b66a3890..d35f7767df 100755
--- a/source4/lib/ldb/tests/python/ldap.py
+++ b/source4/lib/ldb/tests/python/ldap.py
@@ -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:
diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py
index f68f2d12f2..1e39ee8f78 100755
--- a/source4/scripting/bin/winreg.py
+++ b/source4/scripting/bin/winreg.py
@@ -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]
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index a087974a69..dfcf2c457e 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -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):
diff --git a/source4/setup/provision.py b/source4/setup/provision.py
index 88015ce0a3..b9a11bdd78 100755
--- a/source4/setup/provision.py
+++ b/source4/setup/provision.py
@@ -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":
diff --git a/source4/setup/upgrade.py b/source4/setup/upgrade.py
index ea6f83d7de..4cf9641ef2 100755
--- a/source4/setup/upgrade.py
+++ b/source4/setup/upgrade.py
@@ -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)
diff --git a/source4/setup/vampire.py b/source4/setup/vampire.py
index 392cd2d4fb..728c53146a 100755
--- a/source4/setup/vampire.py
+++ b/source4/setup/vampire.py
@@ -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)