[Checkins] SVN: lovely.buildouthttp/trunk/ zc.buildout download support

Bernd Dorn bernd.dorn at lovelysystems.com
Thu May 27 08:09:24 EDT 2010


Log message for revision 112777:
  zc.buildout download support

Changed:
  U   lovely.buildouthttp/trunk/CHANGES.txt
  U   lovely.buildouthttp/trunk/README.txt
  U   lovely.buildouthttp/trunk/bootstrap.py
  U   lovely.buildouthttp/trunk/buildout.cfg
  U   lovely.buildouthttp/trunk/setup.py
  U   lovely.buildouthttp/trunk/src/lovely/buildouthttp/buildouthttp.py

-=-
Modified: lovely.buildouthttp/trunk/CHANGES.txt
===================================================================
--- lovely.buildouthttp/trunk/CHANGES.txt	2010-05-27 11:05:05 UTC (rev 112776)
+++ lovely.buildouthttp/trunk/CHANGES.txt	2010-05-27 12:09:23 UTC (rev 112777)
@@ -2,6 +2,13 @@
 Changes for lovely.buildouthttp
 ===============================
 
+2010/05/27 0.3.0:
+=================
+
+- added support for zc.buildout.download, this allows various download
+  recipes to work with this credential extension. Requires at least
+  zc.buildout version 1.5.0b2
+
 2010/03/24 0.3.0a1:
 ===================
 

Modified: lovely.buildouthttp/trunk/README.txt
===================================================================
--- lovely.buildouthttp/trunk/README.txt	2010-05-27 11:05:05 UTC (rev 112776)
+++ lovely.buildouthttp/trunk/README.txt	2010-05-27 12:09:23 UTC (rev 112777)
@@ -23,6 +23,10 @@
 file ~/.buildout/.httpauth:
 Example com realm, http://www.example.com, username, secret
 
+Note that basic auth also works with any recipe using
+zc.buildout.download (e.g. hexagonit.recipe.download) because this
+extension also overwrites the url opener of zc.buildout.
+
 Github Private Downloads
 ========================
 

Modified: lovely.buildouthttp/trunk/bootstrap.py
===================================================================
--- lovely.buildouthttp/trunk/bootstrap.py	2010-05-27 11:05:05 UTC (rev 112776)
+++ lovely.buildouthttp/trunk/bootstrap.py	2010-05-27 12:09:23 UTC (rev 112777)
@@ -21,20 +21,59 @@
 """
 
 import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
 
 tmpeggs = tempfile.mkdtemp()
 
 is_jython = sys.platform.startswith('java')
 
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+                          help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+                   action="store_true", dest="distribute", default=False,
+                   help="Use Disribute rather than Setuptools.")
+
+parser.add_option("-c", None, action="store", dest="config_file",
+                   help=("Specify the path to the buildout configuration "
+                         "file to be used."))
+
+options, args = parser.parse_args()
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+    args += ['-c', options.config_file]
+
+if options.version is not None:
+    VERSION = '==%s' % options.version
+else:
+    VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
 try:
     import pkg_resources
+    if not hasattr(pkg_resources, '_distribute'):
+        to_reload = True
+        raise ImportError
 except ImportError:
     ez = {}
-    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+    if USE_DISTRIBUTE:
+        exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
                          ).read() in ez
-    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+    else:
+        exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                             ).read() in ez
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
 
-    import pkg_resources
+    if to_reload:
+        reload(pkg_resources)
+    else:
+        import pkg_resources
 
 if sys.platform == 'win32':
     def quote(c):
@@ -49,12 +88,10 @@
 cmd = 'from setuptools.command.easy_install import main; main()'
 ws  = pkg_resources.working_set
 
-if len(sys.argv) > 2 and sys.argv[1] == '--version':
-    VERSION = '==%s' % sys.argv[2]
-    args = sys.argv[3:] + ['bootstrap']
+if USE_DISTRIBUTE:
+    requirement = 'distribute'
 else:
-    VERSION = ''
-    args = sys.argv[1:] + ['bootstrap']
+    requirement = 'setuptools'
 
 if is_jython:
     import subprocess
@@ -63,7 +100,7 @@
            quote(tmpeggs), 'zc.buildout' + VERSION],
            env=dict(os.environ,
                PYTHONPATH=
-               ws.find(pkg_resources.Requirement.parse('setuptools')).location
+               ws.find(pkg_resources.Requirement.parse(requirement)).location
                ),
            ).wait() == 0
 
@@ -73,7 +110,7 @@
         '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
         dict(os.environ,
             PYTHONPATH=
-            ws.find(pkg_resources.Requirement.parse('setuptools')).location
+            ws.find(pkg_resources.Requirement.parse(requirement)).location
             ),
         ) == 0
 

Modified: lovely.buildouthttp/trunk/buildout.cfg
===================================================================
--- lovely.buildouthttp/trunk/buildout.cfg	2010-05-27 11:05:05 UTC (rev 112776)
+++ lovely.buildouthttp/trunk/buildout.cfg	2010-05-27 12:09:23 UTC (rev 112777)
@@ -2,9 +2,12 @@
 develop = .
 parts = test
 extensions = lovely.buildouthttp
+versions = versions
 
 [test]
 recipe = zc.recipe.testrunner
 defaults = ['--auto-color']
 eggs = lovely.buildouthttp [test]
 
+[versions]
+zc.buildout=1.5.0b2

Modified: lovely.buildouthttp/trunk/setup.py
===================================================================
--- lovely.buildouthttp/trunk/setup.py	2010-05-27 11:05:05 UTC (rev 112776)
+++ lovely.buildouthttp/trunk/setup.py	2010-05-27 12:09:23 UTC (rev 112777)
@@ -16,7 +16,7 @@
 name='lovely.buildouthttp'
 setup(
     name = name,
-    version = "0.3.0a1",
+    version = "0.3.0",
     author = "Lovely Systems GmbH",
     author_email = "office at lovelysystems.com",
     description = "Specialized zc.buildout plugin to add http"
@@ -29,7 +29,7 @@
     include_package_data = True,
     package_dir = {'':'src'},
     namespace_packages = ['lovely'],
-    install_requires = ['setuptools'],
+    install_requires = ['setuptools', 'zc.buildout'],
     extras_require = dict(
         test = ['zope.testing']
         ),
@@ -38,7 +38,7 @@
                     },
     zip_safe = False,
     classifiers = [
-       'Development Status :: 4 - Beta',
+       'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: Zope Public License',
        'Topic :: Software Development :: Build Tools',

Modified: lovely.buildouthttp/trunk/src/lovely/buildouthttp/buildouthttp.py
===================================================================
--- lovely.buildouthttp/trunk/src/lovely/buildouthttp/buildouthttp.py	2010-05-27 11:05:05 UTC (rev 112776)
+++ lovely.buildouthttp/trunk/src/lovely/buildouthttp/buildouthttp.py	2010-05-27 12:09:23 UTC (rev 112777)
@@ -22,6 +22,8 @@
 import logging
 import subprocess
 import urllib
+from zc.buildout import download
+import urlparse
 
 log = logging.getLogger('lovely.buildouthttp')
 
@@ -140,6 +142,7 @@
         log.warn('Could not load authentication information: %s' % e)
         return
 
+
     reader = csv.reader(pwdsf)
     auth_handler = CredHandler()
     github_creds = get_github_credentials()
@@ -147,18 +150,19 @@
     if github_creds:
         new_handlers.append(GithubHandler(*github_creds))
 
-    use_auth_handler = False
+    creds = []
     for l, row in enumerate(reader):
         if len(row) != 4:
             raise RuntimeError(
                 "Authentication file cannot be parsed %s:%s" % (
                     pwd_path, l+1))
         realm, uris, user, password = (el.strip() for el in row)
+        creds.append((realm, uris, user, password))
         log.debug('Added credentials %r, %r' % (realm, uris))
         auth_handler.add_password(realm, uris, user, password)
-        use_auth_handler = True
-    if use_auth_handler:
+    if creds:
         new_handlers.append(auth_handler)
+        download.url_opener = URLOpener(creds)
     if new_handlers:
         if urllib2._opener is not None:
             handlers = urllib2._opener.handlers[:]
@@ -167,3 +171,18 @@
             handlers = new_handlers
         opener = urllib2.build_opener(*handlers)
         urllib2.install_opener(opener)
+
+class URLOpener(download.URLOpener):
+
+    def __init__(self, creds):
+        self.creds = {}
+        for realm, uris, user, password in creds:
+            parts = urlparse.urlparse(uris)
+            self.creds[(parts.netloc, realm)] = (user, password)
+        download.URLOpener.__init__(self)
+
+    def prompt_user_passwd(self, host, realm):
+        creds = self.creds.get((host, realm))
+        if creds:
+            return creds
+        return download.URLOpener.prompt_user_passwd(self, host, realm)



More information about the checkins mailing list