[Zope3-checkins] CVS: Zope3/src/zope/configuration - xmlconfig.py:1.21

Jim Fulton jim at zope.com
Mon Mar 1 16:22:39 EST 2004


Update of /cvs-repository/Zope3/src/zope/configuration
In directory cvs.zope.org:/tmp/cvs-serv3989/src/zope/configuration

Modified Files:
	xmlconfig.py 
Log Message:
Added a files attribute to the zcml include directive.  This allows 
multiple files to be included using file-name globs, as in:

<include files="products/*-meta.zcml" />


=== Zope3/src/zope/configuration/xmlconfig.py 1.20 => 1.21 ===
--- Zope3/src/zope/configuration/xmlconfig.py:1.20	Mon Mar  1 08:25:47 2004
+++ Zope3/src/zope/configuration/xmlconfig.py	Mon Mar  1 16:22:08 2004
@@ -25,14 +25,15 @@
 import logging
 import zope.configuration.config as config
 
-from zope import schema
+from glob import glob
 from xml.sax import make_parser
 from xml.sax.xmlreader import InputSource
 from xml.sax.handler import ContentHandler, feature_namespaces
 from xml.sax import SAXParseException
+from zope import schema
 from zope.configuration.exceptions import ConfigurationError
-from zope.interface import Interface
 from zope.configuration.zopeconfigure import IZopeConfigure, ZopeConfigure
+from zope.interface import Interface
 
 logger = logging.getLogger("config")
 
@@ -297,12 +298,36 @@
         including configuration file.
 
         """,
-        default="configure.zcml",
+        required=False,
+        )
+
+    files = schema.BytesLine(
+        __doc__=
+        """Configuration file name pattern
+
+        The names of multiple configuration files to be included,
+        expressed as a file-name pattern, relative to the directive
+        containing the including configuration file.  The pattern can
+        include:
+
+        ``*`` matches 0 or more characters
+
+        ``?`` matches a single character
+
+        [*seq*] matches any character in seq 
+
+        [!*seq*] matches any character not in seq 
+
+        The file names are included in sorted order, where sorting is
+        without regard to case.
+
+        """,
+        required=False,
         )
 
     package = config.fields.GlobalObject(
         __doc__=
-        """Include packahe
+        """Include package
 
         Include the named file (or configure.zcml)
         from the directory of this package.
@@ -311,33 +336,47 @@
         )
 
 
-def include(_context, file, package=None):
+def include(_context, file=None, package=None, files=None):
     """Include a zcml file
 
     See examples in tests/text_xmlconfig.py
     """
 
-    logger.debug("include %s" % file)
+    if files:
+        if file:
+            raise ValueError("Must specify only one of file or files")
+    elif not file:
+        file = 'configure.zcml'
 
     # This is a tad tricky. We want to behave as a grouping directive.
+
     context = config.GroupingContextDecorator(_context)
     if package is not None:
         context.package = package
         context.basepath = None
-    path = context.path(file)
-    context.checkDuplicate(path)
-    f = openInOrPlain(path)
-
-    logger.debug("include %s" % f.name)
-
-    context.basepath = os.path.split(path)[0]
-    context.includepath = _context.includepath + (f.name, )
-    _context.stack.append(config.GroupingStackItem(context))
-
-    processxmlfile(f, context)
-    f.close()
-    assert _context.stack[-1].context is context
-    _context.stack.pop()
+
+    if files:
+        paths = glob(context.path(files))
+        paths = zip([path.lower() for path in paths], paths)
+        paths.sort()
+        paths = [path for (l, path) in paths]
+    else:
+        paths = [context.path(file)]
+    
+    for path in paths:
+        context.checkDuplicate(path)
+
+        f = openInOrPlain(path)
+        logger.debug("include %s" % f.name)
+
+        context.basepath = os.path.split(path)[0]
+        context.includepath = _context.includepath + (f.name, )
+        _context.stack.append(config.GroupingStackItem(context))
+
+        processxmlfile(f, context)
+        f.close()
+        assert _context.stack[-1].context is context
+        _context.stack.pop()
 
 def includeOverrides(_context, file, package=None):
     """Include zcml file containing overrides




More information about the Zope3-Checkins mailing list