summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorGiampaolo Lauria <lauria2@yahoo.com>2011-10-17 15:34:47 -0400
committerJelmer Vernooij <jelmer@samba.org>2011-10-19 03:34:07 +0200
commiteb388cddacb42ae30f4ebb2fc846982132d3ad06 (patch)
tree32b8ba6452b233bbc85b15044eea39525416d0ca /source4/scripting/python
parent20f2034f380cf13b41ad5054a50edef72e18a6c2 (diff)
downloadsamba-eb388cddacb42ae30f4ebb2fc846982132d3ad06.tar.gz
samba-eb388cddacb42ae30f4ebb2fc846982132d3ad06.tar.bz2
samba-eb388cddacb42ae30f4ebb2fc846982132d3ad06.zip
samba-tool: Improve getopt.py error handling
Modified code to handle -k and --kerberos options to: 1. Throw the correct exception 2. On error, display the correct user's specified option
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/samba/getopt.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index 7f500ec63d..68a2cc72f8 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -111,7 +111,7 @@ class VersionOptions(optparse.OptionGroup):
sys.exit(0)
-def parse_kerberos_arg(arg):
+def parse_kerberos_arg(arg, opt_str):
if arg.lower() in ["yes", 'true', '1']:
return MUST_USE_KERBEROS
elif arg.lower() in ["no", 'false', '0']:
@@ -119,7 +119,8 @@ def parse_kerberos_arg(arg):
elif arg.lower() in ["auto"]:
return AUTO_USE_KERBEROS
else:
- raise optparse.BadOptionError("invalid kerberos option: %s" % arg)
+ raise optparse.OptionValueError("invalid %s option value: %s" %
+ (opt_str, arg))
class CredentialsOptions(optparse.OptionGroup):
@@ -165,7 +166,7 @@ class CredentialsOptions(optparse.OptionGroup):
self.ipaddress = arg
def _set_kerberos(self, option, opt_str, arg, parser):
- self.creds.set_kerberos_state(parse_kerberos_arg(arg))
+ self.creds.set_kerberos_state(parse_kerberos_arg(arg, opt_str))
def _set_simple_bind_dn(self, option, opt_str, arg, parser):
self.creds.set_bind_dn(arg)
@@ -229,7 +230,7 @@ class CredentialsOptionsDouble(CredentialsOptions):
self.no_pass2 = False
def _set_kerberos2(self, option, opt_str, arg, parser):
- self.creds2.set_kerberos_state(parse_kerberos_arg(arg))
+ self.creds2.set_kerberos_state(parse_kerberos_arg(arg, opt_str))
def _set_simple_bind_dn2(self, option, opt_str, arg, parser):
self.creds2.set_bind_dn(arg)