summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-04-21 11:33:43 +1000
committerAndrew Tridgell <tridge@samba.org>2010-04-21 13:35:56 +1000
commit024b53755c88855d7e88f256af03bd24280999f0 (patch)
tree3db26fdc1695410e938347bd164cf05dd05eb672 /source4/scripting/python
parent899fa60dd2cf24fc32c83f17080fa5f221861541 (diff)
downloadsamba-024b53755c88855d7e88f256af03bd24280999f0.tar.gz
samba-024b53755c88855d7e88f256af03bd24280999f0.tar.bz2
samba-024b53755c88855d7e88f256af03bd24280999f0.zip
s4-python: accept --option arguments in python cmdline parsing
also fixed the -d option to use lp.set() which calls lp_set_cmdline() Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/samba/getopt.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index 6ec7defde8..6a7e099395 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -29,6 +29,7 @@ __docformat__ = "restructuredText"
class SambaOptions(optparse.OptionGroup):
"""General Samba-related command line options."""
def __init__(self, parser):
+ import os, param
optparse.OptionGroup.__init__(self, parser, "Samba Common Options")
self.add_option("-s", "--configfile", action="callback",
type=str, metavar="FILE", help="Configuration file",
@@ -36,8 +37,11 @@ class SambaOptions(optparse.OptionGroup):
self.add_option("-d", "--debuglevel", action="callback",
type=int, metavar="DEBUGLEVEL", help="debug level",
callback=self._set_debuglevel)
+ self.add_option("--option", action="callback",
+ type=str, metavar="OPTION", help="set smb.conf option from command line",
+ callback=self._set_option)
self._configfile = None
- self._debuglevel = None
+ self._lp = param.LoadParm()
def get_loadparm_path(self):
"""Return the path to the smb.conf file specified on the command line. """
@@ -47,21 +51,24 @@ class SambaOptions(optparse.OptionGroup):
self._configfile = arg
def _set_debuglevel(self, option, opt_str, arg, parser):
- self._debuglevel = arg
+ self._lp.set('debug level', str(arg))
+
+ def _set_option(self, option, opt_str, arg, parser):
+ if arg.find('=') == -1:
+ print("--option takes a 'a=b' argument")
+ sys.exit(1)
+ a = arg.split('=')
+ self._lp.set(a[0], a[1])
def get_loadparm(self):
"""Return a loadparm object with data specified on the command line. """
- import os, param
- lp = param.LoadParm()
if self._configfile is not None:
- lp.load(self._configfile)
+ self._lp.load(self._configfile)
elif os.getenv("SMB_CONF_PATH") is not None:
- lp.load(os.getenv("SMB_CONF_PATH"))
+ self._lp.load(os.getenv("SMB_CONF_PATH"))
else:
- lp.load_default()
- if self._debuglevel:
- samba.set_debug_level(self._debuglevel)
- return lp
+ self._lp.load_default()
+ return self._lp
def get_hostconfig(self):
return Hostconfig(self.get_loadparm())