[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - app.py:1.5

Fred L. Drake, Jr. fred at zope.com
Wed Mar 31 15:31:48 EST 2004


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

Modified Files:
	app.py 
Log Message:
clean up the support code inclusion so both packages are handled in
the same way


=== Packages/zpkgtools/zpkgtools/app.py 1.4 => 1.5 ===
--- Packages/zpkgtools/zpkgtools/app.py:1.4	Wed Mar 31 14:50:55 2004
+++ Packages/zpkgtools/zpkgtools/app.py	Wed Mar 31 15:31:47 2004
@@ -149,39 +149,36 @@
         f.close()
 
     def includeSupportCode(self):
-        zpkgtools_dest = os.path.join(self.destination, "zpkgtools")
-        # Since we might actually be including zpkgtools as an
-        # installable package, we only do this if we need to:
-        if not os.path.exists(zpkgtools_dest):
-            tests_dir = os.path.join(zpkgtools.__path__[0], "tests")
-            self.ip.copyTree(zpkgtools.__path__[0], zpkgtools_dest,
-                             excludes={tests_dir: tests_dir})
-            tests_dir = os.path.join(zpkgtools_dest, "tests")
-        # now we need to find setuptools:
-        setuptools_dest = os.path.join(self.destination, "setuptools")
-        if os.path.exists(setuptools_dest):
-            # already have it
+        self.includeSupportPackage(
+            "zpkgtools", ("cvs://cvs.zope.org/cvs-repository"
+                          ":Packages/zpkgtools/zpkgtools"))
+        self.includeSupportPackage(
+            "setuptools", ("cvs://cvs.python.sourceforge.net/cvsroot/python"
+                           ":python/nondist/sandbox/setuptools/setuptools"))
+
+    def includeSupportPackage(self, name, fallback):
+        destination = os.path.join(self.destination, name)
+        if os.path.exists(destination):
+            # have the package as a side effect of something else
             return
         source = None
-        if "setuptools" in self.locations:
-            url = self.locations["setuptools"]
+        if name in self.locations:
+            url = self.locations[name]
         else:
             try:
-                import setuptools
+                __import__(name)
             except ImportError:
-                # last resort
-                url = ("cvs://cvs.python.sourceforge.net/cvsroot/python"
-                       ":python/nondist/sandbox/setuptools/setuptools")
-                self.logger.info("resource package:setuptools not configured;"
-                                 " using bootstrap URL")
+                url = fallback
+                self.logger.info("resource package:%s not configured;"
+                                 " using fallback URL" % name)
             else:
-                source = os.path.abspath(setuptools.__path__[0])
+                mod = sys.modules[name]
+                source = os.path.abspath(mod.__path__[0])
         if source is None:
             source = self.loader.load(url)
 
         tests_dir = os.path.join(source, "tests")
-        self.ip.copyTree(source, setuptools_dest,
-                         excludes={tests_dir: tests_dir})
+        self.ip.copyTree(source, destination, excludes=[tests_dir])
 
     def createManifest(self):
         if self.ip is None:




More information about the Zope-CVS mailing list