[zpkg] SVN: zpkgtools/trunk/zpkgtools/ make sure that excluded packages with wildcards are reported as errors

Fred L. Drake, Jr. fdrake at gmail.com
Wed Sep 7 19:28:24 EDT 2005


Log message for revision 38371:
  make sure that excluded packages with wildcards are reported as errors
  so that the user can understand what went wrong
  

Changed:
  U   zpkgtools/trunk/zpkgtools/app.py
  U   zpkgtools/trunk/zpkgtools/config.py
  U   zpkgtools/trunk/zpkgtools/config.xml
  U   zpkgtools/trunk/zpkgtools/tests/test_app.py
  U   zpkgtools/trunk/zpkgtools/tests/test_config.py

-=-
Modified: zpkgtools/trunk/zpkgtools/app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/app.py	2005-09-07 22:51:47 UTC (rev 38370)
+++ zpkgtools/trunk/zpkgtools/app.py	2005-09-07 23:28:23 UTC (rev 38371)
@@ -637,6 +637,11 @@
     options, args = parser.parse_args(argv[1:])
     if len(args) > 1:
         parser.error("too many arguments")
+    try:
+        for exclusion in options.exclude_packages:
+            config.resource_name(exclusion)
+    except ValueError, e:
+        parser.error(str(e))
     options.program = prog
     options.args = args
     if args:

Modified: zpkgtools/trunk/zpkgtools/config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/config.py	2005-09-07 22:51:47 UTC (rev 38370)
+++ zpkgtools/trunk/zpkgtools/config.py	2005-09-07 23:28:23 UTC (rev 38371)
@@ -40,6 +40,13 @@
     return string
 
 
+def resource_name(value):
+    value = locationmap.resource_name(value)
+    if value.endswith(".*"):
+        raise ValueError("exclusions do not support wildcards")
+    return value
+
+
 def resource_map(value):
     return value.map
 

Modified: zpkgtools/trunk/zpkgtools/config.xml
===================================================================
--- zpkgtools/trunk/zpkgtools/config.xml	2005-09-07 22:51:47 UTC (rev 38370)
+++ zpkgtools/trunk/zpkgtools/config.xml	2005-09-07 23:28:23 UTC (rev 38371)
@@ -35,7 +35,7 @@
 
   <sectiontype name="exclude"
                datatype=".config.exclude"
-               keytype=".config.non_empty_string"
+               keytype=".config.resource_name"
                >
     <key name="+"
          attribute="mapping"
@@ -64,7 +64,7 @@
        />
 
   <key name="default-collection"
-       datatype=".config.non_empty_string"
+       datatype=".config.resource_name"
        required="no"
        />
 

Modified: zpkgtools/trunk/zpkgtools/tests/test_app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_app.py	2005-09-07 22:51:47 UTC (rev 38370)
+++ zpkgtools/trunk/zpkgtools/tests/test_app.py	2005-09-07 23:28:23 UTC (rev 38371)
@@ -277,7 +277,19 @@
         options = self.parse_args(["--exclude=pkg1", "-xpkg2"])
         self.assertEqual(options.exclude_packages, ["pkg1", "pkg2"])
 
+    def test_exclude_resources_wildcards(self):
+        # excluded packages are not allowed to include wildcards
+        old_stderr = sys.stderr
+        sys.stderr = sio = StringIO()
+        try:
+            self.assertRaises(SystemExit,
+                              self.parse_args, ["-x", "foo.*"])
+        finally:
+            sys.stderr = old_stderr
+        text = sio.getvalue().strip()
+        self.failUnless(text.endswith("exclusions do not support wildcards"))
 
+
 class ComponentTestCase(unittest.TestCase):
 
     def setUp(self):

Modified: zpkgtools/trunk/zpkgtools/tests/test_config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_config.py	2005-09-07 22:51:47 UTC (rev 38370)
+++ zpkgtools/trunk/zpkgtools/tests/test_config.py	2005-09-07 23:28:23 UTC (rev 38371)
@@ -83,6 +83,10 @@
                           self.load_text, ("default-collection foo\n"
                                            "default-collection foo\n"))
 
+        # default-collection with wildcard
+        self.assertRaises(cfgparser.ConfigurationError,
+                          self.load_text, "default-collection foo.*\n")
+
     def test_default_collection(self):
         cf = self.load_text("default-collection foo\n")
         self.assertEqual(cf.default_collection, "foo")
@@ -162,6 +166,14 @@
             "  reportlab   unnecessary junk\n"
             "</exclude>\n")
 
+    def test_exclude_packages_does_not_allow_wildcard(self):
+        self.assertRaises(
+            cfgparser.ConfigurationError,
+            self.load_text,
+            "<exclude>\n"
+            "  reportlab.*\n"
+            "</exclude>\n")
+
     def load_text(self, text, path=None, basedir=None):
         if path is None:
             if basedir is None:



More information about the zpkg mailing list