summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2011-10-12 23:45:52 +0200
committerJelmer Vernooij <jelmer@samba.org>2011-10-13 03:33:20 +0200
commit3978a502438e9a5f9c004401c06ca83a4824327e (patch)
tree050751a483dd70cae535de2aa0baabb25d37f5ae
parent5e04231e961f10656384a6f16104d0d55b6f3e0e (diff)
downloadsamba-3978a502438e9a5f9c004401c06ca83a4824327e.tar.gz
samba-3978a502438e9a5f9c004401c06ca83a4824327e.tar.bz2
samba-3978a502438e9a5f9c004401c06ca83a4824327e.zip
samba.getopt: Refactor parsing of --kerberos argument into separate function.
-rw-r--r--source4/scripting/python/samba/getopt.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index 1b30d2fade..f939180066 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -105,8 +105,20 @@ class VersionOptions(optparse.OptionGroup):
sys.exit(0)
+def parse_kerberos_arg(arg):
+ if arg.lower() in ["yes", 'true', '1']:
+ return MUST_USE_KERBEROS
+ elif arg.lower() in ["no", 'false', '0']:
+ return DONT_USE_KERBEROS
+ elif arg.lower() in ["auto"]:
+ return AUTO_USE_KERBEROS
+ else:
+ raise optparse.BadOptionError("invalid kerberos option: %s" % arg)
+
+
class CredentialsOptions(optparse.OptionGroup):
"""Command line options for specifying credentials."""
+
def __init__(self, parser):
self.no_pass = True
self.ipaddress = None
@@ -147,14 +159,7 @@ class CredentialsOptions(optparse.OptionGroup):
self.ipaddress = arg
def _set_kerberos(self, option, opt_str, arg, parser):
- if arg.lower() in ["yes", 'true', '1']:
- self.creds.set_kerberos_state(MUST_USE_KERBEROS)
- elif arg.lower() in ["no", 'false', '0']:
- self.creds.set_kerberos_state(DONT_USE_KERBEROS)
- elif arg.lower() in ["auto"]:
- self.creds.set_kerberos_state(AUTO_USE_KERBEROS)
- else:
- raise optparse.BadOptionError("invalid kerberos option: %s" % arg)
+ self.creds.set_kerberos_state(parse_kerberos_arg(arg))
def _set_simple_bind_dn(self, option, opt_str, arg, parser):
self.creds.set_bind_dn(arg)
@@ -182,6 +187,7 @@ class CredentialsOptions(optparse.OptionGroup):
class CredentialsOptionsDouble(CredentialsOptions):
"""Command line options for specifying credentials of two servers."""
+
def __init__(self, parser):
CredentialsOptions.__init__(self, parser)
self.no_pass2 = True
@@ -217,10 +223,7 @@ class CredentialsOptionsDouble(CredentialsOptions):
self.no_pass2 = False
def _set_kerberos2(self, option, opt_str, arg, parser):
- if bool(arg) or arg.lower() == "yes":
- self.creds2.set_kerberos_state(MUST_USE_KERBEROS)
- else:
- self.creds2.set_kerberos_state(DONT_USE_KERBEROS)
+ self.creds2.set_kerberos_state(parse_kerberos_arg(arg))
def _set_simple_bind_dn2(self, option, opt_str, arg, parser):
self.creds2.set_bind_dn(arg)
@@ -235,7 +238,7 @@ class CredentialsOptionsDouble(CredentialsOptions):
if guess:
self.creds2.guess(lp)
elif not self.creds2.get_username():
- self.creds2.set_anonymous()
+ self.creds2.set_anonymous()
if self.no_pass2:
self.creds2.set_cmdline_callbacks()