[sylvain] r51161 - buildout/silva/branch/Silva-2.3

[email protected] Fri, 13 Dec 2013 16:14:57 +0100 (CET)
Newsgroups gmane.comp.web.zope.silva.cvs
Message-ID <[email protected]>
Author: sylvain
Date: Fri Dec 13 16:14:57 2013
New Revision: 51161

Modified:
   buildout/silva/branch/Silva-2.3/bootstrap.py
Log:
Update bootstrap.


Modified: buildout/silva/branch/Silva-2.3/bootstrap.py
==============================================================================
--- buildout/silva/branch/Silva-2.3/bootstrap.py	(original)
+++ buildout/silva/branch/Silva-2.3/bootstrap.py	Fri Dec 13 16:14:57 2013
@@ -31,6 +31,9 @@
     help="create a virtualenv to install the software. " \
         "This is recommended if you don't need to rely on globally installed " \
         "libraries")
+parser.add_option(
+    "--verbose", dest="verbose", action="store_true", default=False,
+    help="Display more informations.")
 
 options, args = parser.parse_args()
 
@@ -43,32 +46,51 @@
 to_reload = False
 try:
     import pkg_resources
-    # Verify it is distribute
-    if not hasattr(pkg_resources, '_distribute'):
-        to_reload = True
-        raise ImportError
 except ImportError:
+    # Install setup tools or distribute
+    setup_url = 'http://dist.infrae.com/thirdparty/ez_setup.py'
     ez = {}
-    exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
-                         ).read() in ez
-    ez['use_setuptools'](to_dir=tmp_eggs, download_delay=0, no_fake=True)
+    ez_options = {'to_dir': tmp_eggs, 'download_delay': 0}
+    exec urllib2.urlopen(setup_url).read() in ez
+    ez['use_setuptools'](**ez_options)
 
     if to_reload:
         reload(pkg_resources)
-    else:
-        import pkg_resources
+    import pkg_resources
+
+
+if sys.platform == 'win32':
+    quote = lambda arg: '"%s"' % arg
+else:
+    quote = str
+
+
+def execute(cmd, env=None, stdout=None):
+    if sys.platform == 'win32':
+        # Subprocess doesn't work on windows with setuptools
+        if env:
+            return os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
+        return os.spawnl(*([os.P_WAIT, sys.executable] + cmd))
+    if env:
+        # Keep proxy settings during installation.
+        for key, value in os.environ.items():
+            if key.endswith('_proxy'):
+                env[key] = value
+    stdout = None
+    if not options.verbose:
+        stdout = subprocess.PIPE
+    return subprocess.call(cmd, env=env, stdout=stdout)
 
 
 def install(requirement):
     print "Installing %s ..." % requirement
     cmd = 'from setuptools.command.easy_install import main; main()'
-    if sys.platform == 'win32':
-        cmd = '"%s"' % cmd # work around spawn lamosity on windows
-    distribute_path = pkg_resources.working_set.find(
-        pkg_resources.Requirement.parse('distribute')).location
-    if subprocess.call(
-        [sys.executable, '-c', cmd, '-mqNxd', tmp_eggs, requirement],
-        env={'PYTHONPATH': distribute_path}, stdout=subprocess.PIPE):
+    cmd_path = pkg_resources.working_set.find(
+        pkg_resources.Requirement.parse('setuptools')).location
+    if execute(
+        [sys.executable, '-c', quote(cmd), '-mqNxd', quote(tmp_eggs),
+         '-f', quote('http://pypi.python.org/simple'), '-f', quote('http://dist.infrae.com/thirdparty/'), requirement],
+        env={'PYTHONPATH': cmd_path}):
         sys.stderr.write(
             "\n\nFatal error while installing %s\n" % requirement)
         sys.exit(1)
@@ -80,14 +102,14 @@
 if options.virtualenv:
     python_path = os.path.join(bin_dir, os.path.basename(sys.executable))
     if not os.path.isfile(python_path):
-        install('virtualenv >= 1.5')
+        install('virtualenv>=1.5')
         import virtualenv
         print "Running virtualenv"
         args = sys.argv[:]
         sys.argv = ['bootstrap', os.getcwd(),
-                    '--clear', '--no-site-package', '--distribute']
+                    '--clear', '--no-site-package', '--setuptools']
         virtualenv.main()
-        subprocess.call([python_path] + args)
+        execute([python_path] + args)
         sys.exit(0)
 
 
@@ -104,7 +126,7 @@
     config.close()
 
 
-install('zc.buildout == %s' % options.buildout_version)
+install('zc.buildout==%s' % options.buildout_version)
 import zc.buildout.buildout
 zc.buildout.buildout.main(['-c', options.config, 'bootstrap'])
 
@@ -112,8 +134,8 @@
 if options.install:
     print "Start installation ..."
     # Run install
-    subprocess.call(
-        [sys.executable, os.path.join(bin_dir, 'buildout'),
+    execute(
+        [sys.executable, quote(os.path.join(bin_dir, 'buildout')),
          '-c', options.config, 'install'])
 
 sys.exit(0)