[SCM] Samba Shared Repository - branch master updated
Jelmer Vernooij
jelmer at samba.org
Tue Oct 18 21:05:03 MDT 2011
The branch, master has been updated
via 416bf1c samba.getopt: Add some basic tests.
via aa7240e samba.getopt: Keep exception message when setting a lp option fails.
via eb388cd samba-tool: Improve getopt.py error handling
via 20f2034 samba-tool: Improve getopt.py error handling
via 8dbf799 samba-tool: Improve getopt.py error handling
via 0c342f8 samba-tool: Improve getopt.py error handling
from e1d2b47 s3-docs: Add a clarification note for nss_info primary group membership calculation.
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 416bf1c677e52b52c1447bb0901f9a12930abdf4
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Oct 19 03:35:22 2011 +0200
samba.getopt: Add some basic tests.
Autobuild-User: Jelmer Vernooij <jelmer at samba.org>
Autobuild-Date: Wed Oct 19 05:04:33 CEST 2011 on sn-devel-104
commit aa7240e6cf9d2fcec660116f891fc9c7d6ce39bc
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Wed Oct 19 01:30:40 2011 +0200
samba.getopt: Keep exception message when setting a lp option fails.
commit eb388cddacb42ae30f4ebb2fc846982132d3ad06
Author: Giampaolo Lauria <lauria2 at yahoo.com>
Date: Mon Oct 17 15:34:47 2011 -0400
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
commit 20f2034f380cf13b41ad5054a50edef72e18a6c2
Author: Giampaolo Lauria <lauria2 at yahoo.com>
Date: Mon Oct 17 15:31:30 2011 -0400
samba-tool: Improve getopt.py error handling
Throw an exception when the --option value is invalid
commit 8dbf79941f029e7ddcb347c7436038c47eb8115e
Author: Giampaolo Lauria <lauria2 at yahoo.com>
Date: Mon Oct 17 15:28:52 2011 -0400
samba-tool: Improve getopt.py error handling
Throw an exception when --option value is not in the form "a=b"
commit 0c342f89860a4f64faf62340741b740603907c0e
Author: Giampaolo Lauria <lauria2 at yahoo.com>
Date: Mon Oct 17 15:22:01 2011 -0400
samba-tool: Improve getopt.py error handling
Raise exception when -d or --debuglevel value is <0
-----------------------------------------------------------------------
Summary of changes:
source4/scripting/python/samba/getopt.py | 22 ++++++---
source4/scripting/python/samba/tests/getopt.py | 57 ++++++++++++++++++++++++
source4/selftest/tests.py | 1 +
3 files changed, 73 insertions(+), 7 deletions(-)
create mode 100644 source4/scripting/python/samba/tests/getopt.py
Changeset truncated at 500 lines:
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index f939180..8a9d4e5 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -64,6 +64,9 @@ class SambaOptions(optparse.OptionGroup):
self._configfile = arg
def _set_debuglevel(self, option, opt_str, arg, parser):
+ if arg < 0:
+ raise optparse.OptionValueError("invalid %s option value: %s" %
+ (opt_str, arg))
self._lp.set('debug level', str(arg))
def _set_realm(self, option, opt_str, arg, parser):
@@ -72,10 +75,14 @@ class SambaOptions(optparse.OptionGroup):
def _set_option(self, option, opt_str, arg, parser):
if arg.find('=') == -1:
- print("--option takes a 'a=b' argument")
- sys.exit(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, e:
+ raise optparse.OptionValueError(
+ "invalid --option option value %r: %s" % (arg, e))
def get_loadparm(self):
"""Return loadparm object with data specified on the command line."""
@@ -105,7 +112,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']:
@@ -113,7 +120,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):
@@ -159,7 +167,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)
@@ -223,7 +231,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)
diff --git a/source4/scripting/python/samba/tests/getopt.py b/source4/scripting/python/samba/tests/getopt.py
new file mode 100644
index 0000000..9d72646
--- /dev/null
+++ b/source4/scripting/python/samba/tests/getopt.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2011
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+"""Tests for option parsing.
+
+"""
+
+import optparse
+from samba.getopt import (
+ AUTO_USE_KERBEROS,
+ DONT_USE_KERBEROS,
+ MUST_USE_KERBEROS,
+ parse_kerberos_arg,
+ )
+import samba.tests
+
+class KerberosOptionTests(samba.tests.TestCase):
+
+ def test_parse_true(self):
+ self.assertEquals(
+ MUST_USE_KERBEROS, parse_kerberos_arg("yes", "--kerberos"))
+ self.assertEquals(
+ MUST_USE_KERBEROS, parse_kerberos_arg("true", "--kerberos"))
+ self.assertEquals(
+ MUST_USE_KERBEROS, parse_kerberos_arg("1", "--kerberos"))
+
+ def test_parse_false(self):
+ self.assertEquals(
+ DONT_USE_KERBEROS, parse_kerberos_arg("no", "--kerberos"))
+ self.assertEquals(
+ DONT_USE_KERBEROS, parse_kerberos_arg("false", "--kerberos"))
+ self.assertEquals(
+ DONT_USE_KERBEROS, parse_kerberos_arg("0", "--kerberos"))
+
+ def test_parse_auto(self):
+ self.assertEquals(
+ AUTO_USE_KERBEROS, parse_kerberos_arg("auto", "--kerberos"))
+
+ def test_parse_invalid(self):
+ self.assertRaises(optparse.OptionValueError,
+ parse_kerberos_arg, "blah?", "--kerberos")
diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py
index 7dae7a2..70a0f53 100755
--- a/source4/selftest/tests.py
+++ b/source4/selftest/tests.py
@@ -402,6 +402,7 @@ plantestsuite_idlist("samba.tests.gensec", "dc:local", [subunitrun, "$LISTOPT",
planpythontestsuite("none", "samba.tests.registry")
plansambapythontestsuite("tdb.python", "none", "%s/lib/tdb/python/tests" % srcdir(), 'simple')
planpythontestsuite("none", "samba.tests.auth")
+planpythontestsuite("none", "samba.tests.getopt")
planpythontestsuite("none", "samba.tests.security")
planpythontestsuite("none", "samba.tests.dcerpc.misc")
planpythontestsuite("none", "samba.tests.param")
--
Samba Shared Repository
More information about the samba-cvs
mailing list