[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - include.py:1.42

Fred L. Drake, Jr. fred at zope.com
Thu May 20 12:36:06 EDT 2004


Update of /cvs-repository/Packages/zpkgtools/zpkgtools
In directory cvs.zope.org:/tmp/cvs-serv28265/zpkgtools

Modified Files:
	include.py 
Log Message:
permit components to specify files to exclude from distribution as an
alternative to only allowing specific inclusions to be defined


=== Packages/zpkgtools/zpkgtools/include.py 1.41 => 1.42 ===
--- Packages/zpkgtools/zpkgtools/include.py:1.41	Mon May 17 12:12:16 2004
+++ Packages/zpkgtools/zpkgtools/include.py	Thu May 20 12:35:35 2004
@@ -178,7 +178,13 @@
                                            % typename)
 
     def endSection(self, parent, typename, name, child):
-        pass
+        if child.includes and child.excludes:
+            # XXX not sure what the exact semantics should be of
+            # allowing both inclusions and exclusions at the same
+            # time; which takes precedence?  what about precedence
+            # when wildcards are involved?
+            raise cfgparser.ConfigurationError(
+                "exclusions and inclusions cannot coexist in a single section")
 
     def createSection(self, name, typename, typedef):
         raise NotImplementedError(
@@ -192,6 +198,15 @@
             raise cfgparser.ConfigurationError(
                 "all inclusion lines must be in a section")
 
+        if other == "-":
+            # This is an exclusion.
+            if section.group != "collection":
+                raise cfgparser.ConfigurationError(
+                    "exclusions are only permitted in <collection>")
+            workfile = normalize_path(workfile, "exclusion", section.group)
+            section.excludes.append(workfile)
+            return
+
         if section.group == "load":
             if not other:
                 raise cfgparser.ConfigurationError(
@@ -223,6 +238,9 @@
         source) to either the destination path (relative) or an empty
         string.
 
+      - `excludes`: List of relative paths (relative to the source)
+        which should *not* be copied along with the included files.
+
       - `source`: Source directory which will be used to expand glob
         patterns.
 
@@ -252,6 +270,7 @@
         # The source directory is needed since globbing is performed
         # to locate files if the spec includes wildcards.
         self.includes = {}
+        self.excludes = []
         self.source = source
         self.filename = filename
         self.group = group
@@ -273,6 +292,18 @@
             for fn in expansions:
                 suffix = fn[len(prefix):]
                 self.includes[suffix] = suffix
+        excludes = []
+        for pat in self.excludes:
+            path = os.path.join(source, pat)
+            expansions = filter_names(glob.glob(path))
+            if not expansions:
+                raise InclusionSpecificationError(
+                    "%r doesn't match any files in <%s>" % (pat, self.group),
+                    self.filename)
+            for fn in expansions:
+                suffix = fn[len(prefix):]
+                excludes.append(suffix)
+        self.excludes[:] = excludes
 
 
 class InclusionProcessor:
@@ -308,9 +339,9 @@
             self.create_directory(spec.source, destination)
             self.addIncludes(destination, spec)
         else:
-            self.copyTree(spec.source, destination)
+            self.copyTree(spec.source, destination, spec.excludes)
 
-    def copyTree(self, source, destination):
+    def copyTree(self, source, destination, excludes=()):
         """Populate the destination tree from the source tree.
 
         :Parameters:
@@ -321,6 +352,9 @@
             corresponds to the `source` tree.  It will be created if
             it doesn't exist.
 
+          - `excludes`: Paths relative to source which should be
+            excluded from the copy operation.
+
         Files and directories will be created with the same permission
         bits and stat info as the source tree.
         """
@@ -334,6 +368,17 @@
             # relative to destination.  It will be '' at the top
             # level.
             reldir = dirname[len(prefix):]
+            if excludes:
+                # excludes are in POSIX path notation
+                preldir = reldir.replace(os.sep, "/")
+                for name in dirs[:]:
+                    prelpath = posixpath.join(preldir, name)
+                    if prelpath in excludes:
+                        dirs.remove(name)
+                for name in files[:]:
+                    prelpath = posixpath.join(preldir, name)
+                    if prelpath in excludes:
+                        files.remove(name)
             if reldir:
                 destdir = os.path.join(destination, reldir)
             else:




More information about the Zope-CVS mailing list