[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - app.py:1.44 include.py:1.36 loader.py:1.10

Fred L. Drake, Jr. fred at zope.com
Fri Apr 30 15:28:05 EDT 2004


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

Modified Files:
	app.py include.py loader.py 
Log Message:
- add some logging to help with debugging
- pass a bit more information around so we can resolve repository: URLs in
  the PACKAGE.cfg file effectively
- provide the actual source for a component to addSingleInclude() so it can
  do a required path join with the correct data


=== Packages/zpkgtools/zpkgtools/app.py 1.43 => 1.44 ===
--- Packages/zpkgtools/zpkgtools/app.py:1.43	Fri Apr 30 13:49:12 2004
+++ Packages/zpkgtools/zpkgtools/app.py	Fri Apr 30 15:28:03 2004
@@ -31,6 +31,7 @@
 from zpkgtools import locationmap
 from zpkgtools import package
 from zpkgtools import publication
+from zpkgtools import runlog
 
 
 class Application:
@@ -174,6 +175,7 @@
         deps = self.add_component("collection",
                                   self.resource_name,
                                   self.source,
+                                  self.resource_url,
                                   distribution=True)
         remaining = deps - self.handled_resources
         collections = []
@@ -206,7 +208,7 @@
                               resource, location)
             source = self.loader.load_mutable_copy(location)
             self.handled_resources.add(resource)
-            deps = self.add_component(type, name, source)
+            deps = self.add_component(type, name, source, location)
             if type == "package" and "." in name:
                 # this is a sub-package; always depend on the parent package
                 i = name.rfind(".")
@@ -225,7 +227,7 @@
             f.close()
         return packages, collections
 
-    def add_component(self, type, name, source, distribution=False):
+    def add_component(self, type, name, source, url, distribution=False):
         """Add a single component to a collection.
 
         :return: Set of dependencies for the added component.
@@ -243,6 +245,7 @@
           Directory containing the source of the component.
 
         """
+        self.logger.debug("adding %s:%s (%s) from %s", type, name, url, source)
         if name in self.name_parts:
             self.error("resources of different types share the name %r;"
                        " could not create component directories for each"
@@ -250,7 +253,7 @@
         self.name_parts.add(name)
         destination = os.path.join(self.destination, name)
         self.ip.add_manifest(destination)
-        specs = include.load(source)
+        specs = include.load(source, url=url)
         self.ip.addIncludes(source, specs.loads)
         specs.collection.cook()
         specs.distribution.cook()
@@ -533,7 +536,7 @@
             self.create_tarball()
             self.cleanup()
         except:
-            print >>sys.stderr, "temporary files are in", self.tmpdir
+            print >>sys.stderr, "----\ntemporary files are in", self.tmpdir
             raise
 
 


=== Packages/zpkgtools/zpkgtools/include.py 1.35 => 1.36 ===
--- Packages/zpkgtools/zpkgtools/include.py:1.35	Wed Apr 28 17:03:50 2004
+++ Packages/zpkgtools/zpkgtools/include.py	Fri Apr 30 15:28:03 2004
@@ -29,6 +29,7 @@
 
 import fnmatch
 import glob
+import logging
 import os
 import posixpath
 import shutil
@@ -37,9 +38,13 @@
 from zpkgtools import Error
 
 from zpkgtools import cfgparser
+from zpkgtools import loader
 from zpkgtools import publication
 
 
+logger = logging.getLogger(__name__)
+
+
 # Names that are exluded from globbing results:
 EXCLUDE_NAMES = ["CVS", ".cvsignore", "RCS", "SCCS", ".svn"]
 EXCLUDE_PATTERNS = ["*.py[cdo]", "*.s[ol]", ".#*", "*~"]
@@ -63,14 +68,19 @@
         self.lineno = lineno
 
 
-def load(sourcedir):
+def load(sourcedir, url=None):
     """Return the specifications for populating the distribution and
     collection directories.
 
+    :param sourcedir: Directory we're loading the specifications for.
+
+    :param url: URL used to retrieve `sourcedir`; this is needed to
+      resolve repository: references.
+
     If there is not specification file, return empty specifications.
     """
     package_conf = os.path.join(sourcedir, PACKAGE_CONF)
-    schema = SpecificationSchema(sourcedir, package_conf)
+    schema = SpecificationSchema(sourcedir, package_conf, baseurl=url)
     if os.path.isfile(package_conf):
         f = open(package_conf, "rU")
         try:
@@ -116,11 +126,13 @@
     return np.replace("/", os.sep)
 
 
-def normalize_path_or_url(path, type, group):
+def normalize_path_or_url(path, type, group, baseurl=None):
     if ":" in path:
         scheme, rest = urllib.splittype(path)
         if len(scheme) != 1:
             # should normalize the URL, but skip that for now
+            if baseurl and scheme == "repository":
+                path = loader.join(baseurl, path)
             return path
     return normalize_path(path, type, group)
 
@@ -129,7 +141,8 @@
     """Specialized schema that handles populating a set of Specifications.
     """
 
-    def __init__(self, source, filename):
+    def __init__(self, source, filename, baseurl=None):
+        self.baseurl = baseurl
         self.filename = filename
         self.source = source
 
@@ -177,7 +190,8 @@
                     " in <load> section")
             # perhaps should make sure workfile and other don't refer
             # to the same file
-            other = normalize_path_or_url(other, "source", section.group)
+            other = normalize_path_or_url(other, "source", section.group,
+                                          self.baseurl)
         elif other:
             other = normalize_path(other, "destination", section.group)
 
@@ -383,10 +397,12 @@
 
     def addIncludes(self, destination, spec):
         """Process all the inclusion from a specification."""
+        logger.debug("processing <%s> from %s (dest = %s)",
+                     spec.group, spec.filename, destination)
         for source, relpath in spec.includes.iteritems():
-            self.addSingleInclude(relpath, source, destination)
+            self.addSingleInclude(relpath, source, destination, spec.source)
 
-    def addSingleInclude(self, relpath, source, destination):
+    def addSingleInclude(self, relpath, source, destination, dir=None):
         """Process a single include specification line.
 
         :Parameters:
@@ -400,6 +416,8 @@
             used as a base directory for `relpath`.
 
         """
+        logger.debug("adding include %s from %s (dest = %s)",
+                     relpath, source, destination)
         dirname, basename = os.path.split(relpath)
         if dirname:
             destdir = os.path.join(destination, dirname)
@@ -415,7 +433,7 @@
         type = urllib.splittype(source)[0] or ''
         if len(type) in (0, 1):
             # figure it's a path ref, possibly w/ a Windows drive letter
-            source = os.path.join(self.source, source)
+            source = os.path.join(dir or self.source, source)
             source = "file://" + urllib.pathname2url(source)
             type = "file"
         try:


=== Packages/zpkgtools/zpkgtools/loader.py 1.9 => 1.10 ===
--- Packages/zpkgtools/zpkgtools/loader.py:1.9	Tue Apr 27 14:50:30 2004
+++ Packages/zpkgtools/zpkgtools/loader.py	Fri Apr 30 15:28:03 2004
@@ -17,6 +17,7 @@
 """
 
 import errno
+import logging
 import os
 import posixpath
 import shutil
@@ -29,6 +30,15 @@
 from zpkgtools import svnloader
 
 
+logger = logging.getLogger(__name__)
+
+def trace(msg, *args, **kw):
+    logger.log(5, msg, *args, **kw)
+
+def debug(msg, *args, **kw):
+    logger.debug(msg, *args, **kw)
+
+
 def open(url, mode="r"):
     """Return a file-like object representing the resource at `url`.
 
@@ -100,8 +110,10 @@
             url, (directory, path, istemporary) = self.workdirs.popitem()
             if istemporary:
                 if directory:
+                    trace("removing temp dir %s (%s)", directory, url)
                     shutil.rmtree(directory)
                 else:
+                    trace("removing temp file %s (%s)", path, url)
                     os.unlink(path)
 
     def transform_url(self, url):
@@ -157,6 +169,7 @@
             raise ValueError("can only load from URLs, not path references")
         path = method(url)
         assert path == self.workdirs[url][1]
+        trace("LOADED %s -> %s", url, path)
         return path
 
     def load_mutable_copy(self, url):
@@ -182,6 +195,7 @@
             path = p
         assert path == self.workdirs[url][1]
         assert self.workdirs[url][2]
+        trace("LOADED %s -> %s", url, path)
         return path
 
     def create_copy(self, url, path):
@@ -203,6 +217,8 @@
         path = os.path.normpath(path)
         basename = os.path.basename(path)
         filename = os.path.join(tmpdir, basename)
+        trace("creating mutable copy of %s by copying %s -> %s",
+              url, path, filename)
         if os.path.isfile(path):
             shutil.copy2(path, filename)
         else:
@@ -309,3 +325,25 @@
                          doc="Boolean that indicates whether a space"
                          " character needs to be printed before another"
                          " value when using the ``print`` statement.")
+
+
+#################################################################
+#
+# Generalized URL-handling utilities for CVS and Subversion URLs:
+#
+#################################################################
+
+
+def parse(url):
+    try:
+        return cvsloader.parse(url)
+    except ValueError:
+        return svnloader.parse(url)
+
+def join(base, relurl):
+    r = parse(relurl)
+    if isinstance(r, cvsloader.RepositoryUrl):
+        b = parse(base)
+        return b.join(r).getUrl()
+    else:
+        return relurl




More information about the Zope-CVS mailing list