[Checkins] SVN: z3c.recipe.eggbasket/trunk/ Now also downloading extra Windows specific eggs when creating the

Maurits van Rees m.van.rees at zestsoftware.nl
Thu May 22 19:46:51 EDT 2008


Log message for revision 86911:
  Now also downloading extra Windows specific eggs when creating the
  tarball, as long as they are on the cheese shop.
  

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

-=-
Modified: z3c.recipe.eggbasket/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.eggbasket/trunk/CHANGES.txt	2008-05-22 16:06:58 UTC (rev 86910)
+++ z3c.recipe.eggbasket/trunk/CHANGES.txt	2008-05-22 23:46:49 UTC (rev 86911)
@@ -1,7 +1,10 @@
 0.3.0 (unreleased)
 ==================
 
+ - Now also downloading extra Windows specific eggs when creating the
+   tarball, as long as they are on the cheese shop.  [maurits]
 
+
 0.2.0 (22 May 2008)
 ===================
 

Modified: z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/utils.py
===================================================================
--- z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/utils.py	2008-05-22 16:06:58 UTC (rev 86910)
+++ z3c.recipe.eggbasket/trunk/z3c/recipe/eggbasket/utils.py	2008-05-22 23:46:49 UTC (rev 86911)
@@ -1,7 +1,11 @@
+import logging
+import os.path
+import re
+import shutil
 import sys
+import tarfile
 import tempfile
-import shutil
-import tarfile
+import urllib
 
 
 def install_distributions(distributions, target_dir, links=[]):
@@ -33,12 +37,14 @@
 
 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
         # directory and get an egg name and perhaps version number
         # from there would be cool.  For now:
-        print "Please provide an egg name."
+        log.error("Please provide an egg name.")
         sys.exit(1)
 
     # XXX This may be a bit too hard coded.
@@ -47,7 +53,6 @@
 
     import zc.buildout.easy_install
     import zc.buildout.buildout
-    import os
 
     # Read the buildout/versions file.  versionfile can be a file in
     # the current working directory or on some url.  zc.buildout
@@ -63,7 +68,7 @@
         if versions is not None:
             versions = config.get(versions)
     if versions is None:
-        print "Could not get versions from %s." % versionfile
+        log.error("Could not get versions from %s.", versionfile)
         sys.exit(1)
 
     try:
@@ -77,24 +82,37 @@
 
         main_egg_version = versions.get(egg)
         if main_egg_version is None:
-            print ("Error: the main egg (%s) has not been pinned in the "
-                   "version file (%s)." % (egg, versionfile))
+            log.error("The main egg (%s) has not been pinned in the "
+                      "version file (%s)." % (egg, versionfile))
             sys.exit(1)
 
         # Install the main egg, which pulls all dependencies into the
         # download cache.
-        print ("Will get main egg (%s) version %s and dependencies "
-               "with versions as listed in %s." %
-               (egg, main_egg_version, versionfile))
-        print "This could take a while..."
+        log.info("Will get main egg (%s) version %s and dependencies "
+                 "with versions as listed in %s." %
+                 (egg, main_egg_version, versionfile))
+        log.info("This could take a while...")
         ws = zc.buildout.easy_install.install(
             [egg], dest, versions=versions,
             links=links)
 
+        # TODO: Make this optional:
+        log.info("Getting extra Windows distributions...")
+        egg_expression = re.compile(r'(.*)-([^-]*)(\.tar.gz|-py-*\.egg)')
+        for package in os.listdir(cache):
+            results = egg_expression.findall(package)
+            if len(results) != 1:
+                continue
+            parts = results[0]
+            if len(parts) != 3:
+                continue
+            package, version, dummy = parts
+            get_windows_egg(package, version, cache)
+
         # Create tarball in current directory.
         directory_name = '%s-eggs-%s' % (egg, main_egg_version)
         tar_name = directory_name + '.tgz'
-        print "Creating", tar_name
+        log.info("Creating %s", tar_name)
         egg_tar = tarfile.open(tar_name, 'w:gz')
         egg_tar.add(cache, directory_name)
 
@@ -102,7 +120,48 @@
         # is not there already, though currently the code should have
         # failed already when this it is not available.
         egg_tar.close()
-        print "Done."
+        log.info("Done.")
     finally:
         shutil.rmtree(dest)
         shutil.rmtree(cache)
+
+
+def get_windows_egg(package, version, target_dir):
+    log = logging.getLogger('eggbasket.utils')
+    base_url = 'http://pypi.python.org/simple/'
+    package_page = base_url + package
+    try:
+        contents = urllib.urlopen(package_page).read()
+    except IOError:
+        log.warn("%s not found.", package_page)
+        return
+
+    # We expect to get html with lines like this:
+    #
+    # <a href='http://pypi.python.org/packages/source/m/martian/martian-0.9.6.tar.gz#md5=98cda711bda0c5f45a05e2bdc2dc0d23'>martian-0.9.6.tar.gz</a><br/>
+    #
+    # We want to look for http....package-version-py2.x-win32.egg
+    expression = r'[\'"]http.*/%s-%s-py.*win32.egg.*[\'"]' % (package, version)
+    findings = re.compile(expression).findall(contents)
+    log.debug("Found %s matches.", len(findings))
+    for finding in findings:
+        # Strip off the enclosing single or double quotes:
+        finding = finding[1:-1]
+        # We probably have something like:
+        # ...egg#md5=3fa5e992271375eac597622d8e2fd5ec'
+        parts = finding.split('#md5=')
+        url = parts[0]
+        if len(parts) == 2:
+            md5hash = parts[1]
+        else:
+            md5hash = ''
+
+        target = os.path.join(target_dir, url.split('/')[-1])
+        log.info("Downloading %s to %s", url, target)
+        try:
+            urllib.urlretrieve(url, target)
+        except IOError:
+            log.error("Download error.")
+        else:
+            log.info("Finished downloading.")
+            # TODO: check md5hash



More information about the Checkins mailing list