[Checkins] SVN: zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py Using get_metadata and metadata_listdir/isdir methods according to PJE's hint.

Reinout van Rees reinout at vanrees.org
Tue Sep 8 04:30:48 EDT 2009


Log message for revision 103628:
  Using get_metadata and metadata_listdir/isdir methods according to PJE's hint.
  I could remove 18 lines of code in exchange for just 4: much more robust.

Changed:
  U   zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py

-=-
Modified: zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py	2009-09-08 08:27:16 UTC (rev 103627)
+++ zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py	2009-09-08 08:30:48 UTC (rev 103628)
@@ -33,7 +33,6 @@
 import sys
 import tempfile
 import zc.buildout
-import zipfile
 import zipimport
 
 _oprp = getattr(os.path, 'realpath', lambda path: path)
@@ -943,23 +942,10 @@
             # The metadata on "old-style" distutils scripts is not retained by
             # distutils/setuptools, except by placing the original scripts in
             # /EGG-INFO/scripts/.
-            if os.path.isdir(dist.location):
-                # Unzipped egg: use os.listdir() to detect possible scripts.
-                scripts_dir = os.path.join(dist.location, 'EGG-INFO', 'scripts')
-                if os.path.exists(scripts_dir):
-                    for name in os.listdir(scripts_dir):
-                        contents = open(os.path.join(scripts_dir, name)
-                                        ).read()
-                        distutils_scripts.append(
-                            (name, contents))
-            else:
-                # Zipped egg: use zipfile to detect possible scripts.
-                zipped = zipfile.ZipFile(dist.location)
-                for filepath in zipped.namelist():
-                    if filepath.startswith('EGG-INFO/scripts'):
-                        name = os.path.basename(filepath)
-                        contents = zipped.read(filepath)
-                        distutils_scripts.append((name, contents))
+            if dist.metadata_isdir('scripts'):
+                for name in dist.metadata_listdir('scripts'):
+                    contents = dist.get_metadata('scripts/%s' % name)
+                    distutils_scripts.append((name, contents))
         else:
             entry_points.append(req)
 



More information about the checkins mailing list