[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - locationmap.py:1.6

Fred L. Drake, Jr. fred at zope.com
Thu Mar 18 16:03:37 EST 2004


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

Modified Files:
	locationmap.py 
Log Message:
when a map contains more than one entry for a resource, issue a
warning for the user


=== Packages/zpkgtools/zpkgtools/locationmap.py 1.5 => 1.6 ===
--- Packages/zpkgtools/zpkgtools/locationmap.py:1.5	Wed Mar 10 15:48:15 2004
+++ Packages/zpkgtools/zpkgtools/locationmap.py	Thu Mar 18 16:03:36 2004
@@ -11,10 +11,12 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Tools to deal with the mapping of resources to CVS URLs."""
+"""Tools to deal with the mapping of resources to URLs."""
 
+import logging
 import os.path
 import posixpath
+import sets
 import urllib
 import urllib2
 import urlparse
@@ -23,11 +25,15 @@
 from zpkgtools import cvsloader
 
 
+_logger = logging.getLogger(__name__)
+
+
 DEFAULT_TYPE = "package"
 
 
 class MapLoadingError(ValueError):
-    def __init__(self, message, lineno):
+    def __init__(self, message, filename, lineno):
+        self.filename = filename
         self.lineno = lineno
         ValueError.__init__(self, message)
 
@@ -69,6 +75,7 @@
             pass
     if mapping is None:
         mapping = LocationMap()
+    local_entries = sets.Set()
     lineno = 0
     for line in f:
         lineno += 1
@@ -78,7 +85,8 @@
 
         parts = line.split()
         if len(parts) != 2:
-            raise MapLoadingError("malformed package specification", lineno)
+            raise MapLoadingError("malformed package specification",
+                                  getattr(f, "name", "<unknown>"), lineno)
         resource, url = parts
         resource = normalizeResourceId(resource)
         try:
@@ -93,7 +101,7 @@
                     raise MapLoadingError(
                         "repository: URLs are not supported"
                         " without a cvs: base URL",
-                        lineno)
+                        getattr(f, "name", "<unknown>"), lineno)
                 cvsurl = cvsbase.join(cvsurl)
             url = cvsurl.getUrl()
 
@@ -101,6 +109,11 @@
         # mappings causes the first defining a resource to "win":
         if resource not in mapping:
             mapping[resource] = url
+        elif resource in local_entries:
+            _logger.warn(
+                "found duplicate entry for resource %r in %s at line %d",
+                resource, getattr(f, "name", "<unknown>"), lineno)
+        local_entries.add(resource)
         # else tell the user of the conflict?
 
     return mapping




More information about the Zope-CVS mailing list