Commits

Anonymous committed 79b49c3

a setuptools can be present here, we need to get it out of the way

Comments (0)

Files changed (1)

 
 $Id$
 """
-
+import time
 import os, shutil, sys, tempfile, urllib2
 
 tmpeggs = tempfile.mkdtemp()
                 else:
                     shutil.copy2(dist.location, dest)
 
-    import sys
+    import sys, time
     egg_directory = self['buildout']['eggs-directory']
     pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
     setuptools_name = 'setuptools-0.6c9-py%s.egg' % pyver
                             'Author-email: xxx',
                             'License: xxx',
                             'Description: xxx']
+    SETUPTOOLS_PKG_INFO = '\n'.join(SETUPTOOLS_PKG_INFO)
+    fake_setuptools = os.path.join(egg_directory, setuptools_name)
+    egg_info = os.path.join(fake_setuptools, 'EGG-INFO')
+    pkg_info = os.path.join(egg_info, 'PKG-INFO')
 
-    fake_setuptools = os.path.join(egg_directory, setuptools_name)
+    already_patched = False
+    if os.path.exists(fake_setuptools):
+        # checking if it's a real setuptools or a fake one
+        if os.path.exists(pkg_info):
+            f = open(pkg_info)
+            content = f.read()
+            f.close()
+            already_patched = content == SETUPTOOLS_PKG_INFO
+
+    if not already_patched:
+        if os.path.exists(fake_setuptools):
+            new_name = fake_setuptools + '.OLD.%s' % time.time()
+            os.rename(fake_setuptools, new_name)
+
+        os.mkdir(fake_setuptools)
+        os.mkdir(egg_info)
+        f = open(pkg_info, 'w')
+        try:
+            f.write(SETUPTOOLS_PKG_INFO)
+        finally:
+            f.close()
+
     entries.append(fake_setuptools)
 
-    if not os.path.exists(fake_setuptools):
-        os.mkdir(fake_setuptools)
-        os.mkdir(os.path.join(fake_setuptools, 'EGG-INFO'))
-        pkg_info = os.path.join(fake_setuptools, 'EGG-INFO', 'PKG-INFO')
-        f = open(pkg_info, 'w')
-        try:
-            f.write('\n'.join(SETUPTOOLS_PKG_INFO))
-        finally:
-            f.close()
     # Create buildout script
     ws = pkg_resources.WorkingSet(entries)
     ws.require('zc.buildout')