[Zope3-checkins] CVS: Zope3/lib/python/Zope/Configuration - xmlconfig.py:1.12

Marius Gedminas mgedmin@codeworks.lt
Thu, 12 Dec 2002 11:46:44 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Configuration
In directory cvs.zope.org:/tmp/cvs-serv3327/lib/python/Zope/Configuration

Modified Files:
	xmlconfig.py 
Log Message:
Allow <include package="foo.bar.*" /> in zcml.  This will include every
subpackage of foo.bar which contains a 'configure.zcml' file.



=== Zope3/lib/python/Zope/Configuration/xmlconfig.py 1.11 => 1.12 ===
--- Zope3/lib/python/Zope/Configuration/xmlconfig.py:1.11	Mon Dec  9 10:59:12 2002
+++ Zope3/lib/python/Zope/Configuration/xmlconfig.py	Thu Dec 12 11:46:43 2002
@@ -287,7 +287,14 @@
     def include(self, _context, file='configure.zcml', package=None):
         if package is None and _context.packageWasSet():
             package = _context.package()
+        subpackages = False
         if package is not None:
+            if package.endswith('.*'):
+                # <include package="package.*" /> includes all subpackages
+                subpackages = True
+                parent = package = package[:-2]
+                if package == "":
+                    package = "."
             try:
                 package = _context.resolve(package)
                 if len(package.__path__) != 1:
@@ -306,7 +313,20 @@
         else:
             prefix = os.path.dirname(self._stack[-1])
 
-        file_name = os.path.join(prefix, file)
+        if subpackages:
+            for subdir in os.listdir(prefix):
+                file_name = os.path.join(prefix, subdir, file)
+                if not os.access(file_name, os.F_OK):
+                    continue
+                subpackage = "%s.%s" % (parent, subdir)
+                subpackage = _context.resolve(subpackage)
+                self._include(file_name, subpackage)
+        else:
+            file_name = os.path.join(prefix, file)
+            self._include(file_name, package)
+        return ()
+
+    def _include(self, file_name, package):
 
         f = open(file_name)
         self._stack.append(file_name)
@@ -314,7 +334,6 @@
                   self._directives)
         self._stack.pop()
         f.close()
-        return ()
 
     def __call__(self):
         self.organize()