samba-tool: Improve getopt.py error handling
authorGiampaolo Lauria <lauria2@yahoo.com>
Mon, 17 Oct 2011 19:31:30 +0000 (15:31 -0400)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 19 Oct 2011 01:34:07 +0000 (03:34 +0200)
Throw an exception when the --option value is invalid

source4/scripting/python/samba/getopt.py

index 14cfba62410d2d02545c7d88e80e728223caa2a6..7f500ec63da2d6e12a6665ea06e515cefebe3960 100644 (file)
@@ -77,7 +77,11 @@ class SambaOptions(optparse.OptionGroup):
         if arg.find('=') == -1:
             raise optparse.OptionValueError("--option option takes a 'a=b' argument")
         a = arg.split('=')
-        self._lp.set(a[0], a[1])
+        try:
+            self._lp.set(a[0], a[1])
+        except Exception:
+            raise optparse.OptionValueError("invalid --option option value: %s"
+                                            % arg)
 
     def get_loadparm(self):
         """Return loadparm object with data specified on the command line."""