[Checkins] SVN: z3c.recipe.eggbasket/trunk/ Fixed temp dir removal error on Windows (fix makes the code saner

Maurits van Rees m.van.rees at zestsoftware.nl
Mon Jan 12 04:47:18 EST 2009


Log message for revision 94692:
  Fixed temp dir removal error on Windows (fix makes the code saner
  for other systems too).  Fixes https://bugs.launchpad.net/grok/+bug/315227
  

Changed:
  U   z3c.recipe.eggbasket/trunk/CHANGES.txt
  U   z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/README.txt
  U   z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/downloader.py
  U   z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/utils.py

-=-
Modified: z3c.recipe.eggbasket/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.eggbasket/trunk/CHANGES.txt	2009-01-12 05:04:15 UTC (rev 94691)
+++ z3c.recipe.eggbasket/trunk/CHANGES.txt	2009-01-12 09:47:18 UTC (rev 94692)
@@ -1,6 +1,10 @@
 0.4.1 (unreleased)
 ==================
 
+* Fixed temp dir removal error on Windows (fix makes the code saner
+  for other systems too).  Fixes
+  https://bugs.launchpad.net/grok/+bug/315227
+
 * Windows compatibility fix: use ``'wb'`` for writing to make downloading
   of the egg tarball succeeds on Windows.
 

Modified: z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/README.txt
===================================================================
--- z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/README.txt	2009-01-12 05:04:15 UTC (rev 94691)
+++ z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/README.txt	2009-01-12 09:47:18 UTC (rev 94692)
@@ -133,10 +133,7 @@
 used.  Running the buildout gives us::
 
     >>> print system(buildout)
-    Upgraded:
-      zc.buildout version ...;
-    restarting.
-    Generated script '/sample-buildout/bin/buildout'.
+    ...
     Installing basket.
     <BLANKLINE>
 
@@ -160,10 +157,14 @@
     >>> cd(tarserver)
     >>> tarball = tarfile.open('colours.tgz', 'w:gz')
     >>> tarball.add(colours)
+
+Note: the order of the next listing is not guaranteed, so there might
+be a test failure here:
+
     >>> tarball.list(verbose=False)
     tmp/tmpDlQSIQbuildoutSetUp/_TEST_/colours/
+    tmp/tmpDlQSIQbuildoutSetUp/_TEST_/colours/orange-0.1.zip
     tmp/tmpDlQSIQbuildoutSetUp/_TEST_/colours/colour-0.1.zip
-    tmp/tmpDlQSIQbuildoutSetUp/_TEST_/colours/orange-0.1.zip
     >>> tarball.close()
     >>> ls(tarserver)
     -  colours.tgz
@@ -184,7 +185,9 @@
     basket: Extracting tarball contents...
     basket: Installing eggs to .../sample-buildout/eggs which will take a while...
     Getting distribution for 'orange'.
+    ...
     Got orange 0.1.
     Getting distribution for 'colour'.
+    ...
     Got colour 0.1.
     <BLANKLINE>

Modified: z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/downloader.py
===================================================================
--- z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/downloader.py	2009-01-12 05:04:15 UTC (rev 94691)
+++ z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/downloader.py	2009-01-12 09:47:18 UTC (rev 94692)
@@ -38,11 +38,16 @@
             tarball_name = url.split('/')[-1]
             log.info("Downloading %s ..." % url)
 
+            # Make temporary files and directories.
             try:
-                # Make temporary files and directories.
                 extraction_dir = tempfile.mkdtemp()
                 filenum, temp_tarball_name = tempfile.mkstemp()
-
+            except:
+                log.error("Could not create temporary file or directory")
+                # Reraise exception
+                raise
+            try:
+                # Note: 'b' mode needed for Windows.
                 tarball = open(temp_tarball_name, 'wb')
                 try:
                     tarball.write(urllib.urlopen(url).read())
@@ -77,8 +82,8 @@
                     log.error("Failed to install required eggs with the tar "
                               "ball.")
             finally:
+                os.unlink(temp_tarball_name)
                 shutil.rmtree(extraction_dir)
-                os.unlink(temp_tarball_name)
 
         # Return files that were created by the recipe. The buildout
         # will remove all returned files upon reinstall.

Modified: z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/utils.py
===================================================================
--- z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/utils.py	2009-01-12 05:04:15 UTC (rev 94691)
+++ z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/utils.py	2009-01-12 09:47:18 UTC (rev 94692)
@@ -7,7 +7,11 @@
 import tempfile
 import urllib
 
+# XXX We may want to add command line argument handling.
+logging.basicConfig(level=logging.INFO,
+                    format='%(levelname)-5s %(name)-12s %(message)s')
 
+
 def install_distributions(distributions, target_dir, links=[],
                           use_empty_index=False):
     """Install distributions.
@@ -21,15 +25,24 @@
     """
     from zc.buildout.easy_install import install
     from zc.buildout.easy_install import MissingDistribution
-    try:
-        empty_index = tempfile.mkdtemp()
-        if use_empty_index:
-            index = 'file://' + empty_index
-        else:
-            # Use the default index (python cheese shop)
-            index = None
+    log = logging.getLogger('eggbasket.utils')
 
+    if use_empty_index:
+        # When the temp dir is not writable this throws an OSError,
+        # which we might want to catch, but actually it is probably
+        # fine to just let it bubble up to the user.
         try:
+            empty_index = tempfile.mkdtemp()
+        except:
+            log.error("Could not create temporary file")
+            # Reraise exception
+            raise
+        index = 'file://' + empty_index
+    else:
+        # Use the default index (python cheese shop)
+        index = None
+    try:
+        try:
             install(distributions, target_dir, newest=False,
                     links=links, index=index)
         except MissingDistribution:
@@ -37,7 +50,8 @@
         else:
             return True
     finally:
-        shutil.rmtree(empty_index)
+        if use_empty_index:
+            shutil.rmtree(empty_index)
 
 
 def distributions_are_installed_in_dir(distributions, target_dir):
@@ -51,9 +65,6 @@
 
 
 def create_source_tarball(egg=None, versionfile='buildout.cfg'):
-    # XXX We may want to add command line argument handling.
-    logging.basicConfig(level=logging.INFO,
-                        format='%(levelname)-5s %(name)-12s %(message)s')
     log = logging.getLogger('eggbasket.utils')
     if egg is None:
         # XXX Having a way to read the setup.py in the current



More information about the Checkins mailing list