[sylvain] r51206 - in buildout/silva/branch/Silva-2.1: . profiles

[email protected] Tue, 18 Feb 2014 10:27:49 +0100 (CET)
Newsgroups gmane.comp.web.zope.silva.cvs
Message-ID <[email protected]>
Author: sylvain
Date: Tue Feb 18 10:27:49 2014
New Revision: 51206

Modified:
   buildout/silva/branch/Silva-2.1/bootstrap.py
   buildout/silva/branch/Silva-2.1/profiles/base.cfg
Log:
Update SilvaNews/setuptools/buildout and clean find-links.


Modified: buildout/silva/branch/Silva-2.1/bootstrap.py
==============================================================================
--- buildout/silva/branch/Silva-2.1/bootstrap.py	(original)
+++ buildout/silva/branch/Silva-2.1/bootstrap.py	Tue Feb 18 10:27:49 2014
@@ -1,96 +1,282 @@
-##############################################################################
-#
-# Copyright (c) 2006 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Bootstrap a buildout-based project
-
-Simply run this script in a directory containing a buildout.cfg.
-The script accepts buildout command-line options, so you can
-use the -c option to specify an alternate configuration file.
-
-$Id$
+"""Bootstrap a buildout-based project, including downloading and
+installing setuptools.
 """
 
-import os, os.path, shutil, sys, tempfile, urllib2
+from distutils import log
+from optparse import OptionParser
+import atexit
+import os
+import shutil
+import subprocess
+import sys
+import tarfile
+import tempfile
+import urllib2
+
+if sys.version_info[1] < 5:
+    # No HTTPS for Python 2.4 this isn't supported.
+    VIRTUALENV_REQ = "virtualenv<1.7"
+    SETUPTOOLS_VERSION = "1.4.2"
+    SETUPTOOLS_URL = "http://dist.infrae.com/thirdparty/"
+else:
+    VIRTUALENV_REQ= "virtualenv>=1.5"
+    SETUPTOOLS_VERSION = "2.0.1"
+    SETUPTOOLS_URL = "https://pypi.python.org/packages/source/s/setuptools/"
+
+parser = OptionParser(usage="python bootstrap.py\n\n"
+                      "Bootstrap the installation process.",
+                      version="bootstrap.py $Revision$")
+parser.add_option(
+    "--buildout-config", dest="config", default="buildout.cfg",
+    help="specify buildout configuration file to use, default to buildout.cfg")
+parser.add_option(
+    "--buildout-profile", dest="profile",
+    help="specify a buildout profile to extends as configuration")
+parser.add_option(
+    "--buildout-version", dest="buildout_version", default="1.4.4",
+    help="specify version of zc.buildout to use, default to 1.4.4")
+parser.add_option(
+    "--install", dest="install", action="store_true", default=False,
+    help="directly start the install process after bootstrap")
+parser.add_option(
+    "--virtualenv", dest="virtualenv", action="store_true", default=False,
+    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.")
 
-tmpeggs = tempfile.mkdtemp()
+options, args = parser.parse_args()
 
-enable_virtualenv = False
-if '--virtualenv' in sys.argv:
-    enable_virtualenv = True
-    sys.argv.remove('--virtualenv')
-
-if '--buildout-profile' in sys.argv:
-    index = sys.argv.index('--buildout-profile') + 1
-    if index > len(sys.argv):
-        raise ValueError, '--buildout-profile require a config file.'
-    buildout_config = sys.argv[index]
-    if not os.path.isfile(buildout_config):
-        raise ValueError, 'no such configuration file.'
+bin_dir = 'bin'
+quote = str
+if sys.platform.startswith('win'):
+    bin_dir = 'Scripts'
+    quote = lambda arg: '"%s"' % arg
+tmp_eggs = tempfile.mkdtemp()
+atexit.register(shutil.rmtree, tmp_eggs)
+
+
+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 extract_tar(tar, path=".", members=None):
+    """Extract all members from the archive to the current working
+       directory and set owner, modification time and permissions on
+       directories afterwards. `path' specifies a different directory
+       to extract to. `members' is optional and must be a subset of the
+       list returned by getmembers().
+    """
+    import copy
+    import operator
+    from tarfile import ExtractError
+    directories = []
+
+    if members is None:
+        members = tar
+
+    for tarinfo in members:
+        if tarinfo.isdir():
+            # Extract directories with a safe mode.
+            directories.append(tarinfo)
+            tarinfo = copy.copy(tarinfo)
+            tarinfo.mode = 448  # decimal for oct 0700
+        tar.extract(tarinfo, path)
+
+    # Reverse sort directories.
+    if sys.version_info < (2, 4):
+        def sorter(dir1, dir2):
+            return cmp(dir1.name, dir2.name)
+        directories.sort(sorter)
+        directories.reverse()
+    else:
+        directories.sort(key=operator.attrgetter('name'), reverse=True)
+
+    # Set correct owner, mtime and filemode on directories.
+    for tarinfo in directories:
+        dirpath = os.path.join(path, tarinfo.name)
+        try:
+            tar.chown(tarinfo, dirpath)
+            tar.utime(tarinfo, dirpath)
+            tar.chmod(tarinfo, dirpath)
+        except ExtractError:
+            e = sys.exc_info()[1]
+            if tar.errorlevel > 1:
+                raise
+            else:
+                tar._dbg(1, "tarfile: %s" % e)
+
+
+def build_egg(egg, tarball, to_dir):
+    # extracting the tarball
+    tmpdir = tempfile.mkdtemp()
+    log.warn('Extracting ...')
+    old_wd = os.getcwd()
+    try:
+        os.chdir(tmpdir)
+        tar = tarfile.open(tarball)
+        extract_tar(tar)
+        tar.close()
+
+        # going in the directory
+        os.chdir(os.path.join(tmpdir, os.listdir(tmpdir)[0]))
+        # building an egg
+        log.warn('Installing setuptools ...')
+        execute([sys.executable, 'setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir])
+
+    finally:
+        os.chdir(old_wd)
+        shutil.rmtree(tmpdir)
+    if not os.path.exists(egg):
+        raise IOError('Could not build the egg.')
+
+
+def download_setuptools(version, download_base, to_dir):
+    """Download setuptools from a specified location and return its filename
+
+    `version` should be a valid setuptools version number that is available
+    as an egg for download under the `download_base` URL (which should end
+    with a '/'). `to_dir` is the directory where the egg will be downloaded.
+    """
+    # making sure we use the absolute path
+    to_dir = os.path.abspath(to_dir)
+    tgz_name = "setuptools-%s.tar.gz" % version
+    url = download_base + tgz_name
+    saveto = os.path.join(to_dir, tgz_name)
+    src = dst = None
+    if not os.path.exists(saveto):  # Avoid repeated downloads
+        try:
+            log.warn("Downloading %s", url)
+            src = urllib2.urlopen(url)
+            # Read/write all in one block, so we don't create a corrupt file
+            # if the download is interrupted.
+            data = src.read()
+            dst = open(saveto, "wb")
+            dst.write(data)
+        finally:
+            if src:
+                src.close()
+            if dst:
+                dst.close()
+    return os.path.realpath(saveto)
+
+
+def _do_download(version, download_base, to_dir):
+    egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
+                       % (version, sys.version_info[0], sys.version_info[1]))
+    if not os.path.exists(egg):
+        tarball = download_setuptools(version, download_base, to_dir)
+        build_egg(egg, tarball, to_dir)
+    sys.path.insert(0, egg)
+    import setuptools
+    setuptools.bootstrap_install_from = egg
+
+
+def install_setuptools(version=SETUPTOOLS_VERSION,
+                       download_base=SETUPTOOLS_URL,
+                       to_dir=tmp_eggs):
+    # making sure we use the absolute path
+    to_dir = os.path.abspath(to_dir)
+    was_imported = 'pkg_resources' in sys.modules or \
+        'setuptools' in sys.modules
+    try:
+        import pkg_resources
+    except ImportError:
+        return _do_download(version, download_base, to_dir)
+    try:
+        pkg_resources.require("setuptools>=" + version)
+        return
+    except pkg_resources.VersionConflict:
+        e = sys.exc_info()[1]
+        if was_imported:
+            sys.stderr.write(
+            "The required version of setuptools (>=%s) is not available,\n"
+            "and can't be installed while this script is running. Please\n"
+            "install a more recent version first, using\n"
+            "'easy_install -U setuptools'."
+            "\n\n(Currently using %r)\n" % (version, e.args[0]))
+            sys.exit(2)
+        else:
+            del pkg_resources, sys.modules['pkg_resources']    # reload ok
+            return _do_download(version, download_base, to_dir)
+    except pkg_resources.DistributionNotFound:
+        return _do_download(version, download_base, to_dir)
+
+
+install_setuptools()
+import pkg_resources
+
+
+def install(requirement):
+    print "Installing %s ..." % requirement
+    cmd = 'from setuptools.command.easy_install import main; main()'
+    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)
+
+    pkg_resources.working_set.add_entry(tmp_eggs)
+    pkg_resources.working_set.require(requirement)
+
+
+if options.virtualenv:
+    python_path = os.path.join(bin_dir, os.path.basename(sys.executable))
+    if not os.path.isfile(python_path):
+        install(VIRTUALENV_REQ)
+        import virtualenv
+        print "Running virtualenv"
+        args = sys.argv[:]
+        sys.argv = ['bootstrap', os.getcwd(),
+                    '--clear', '--no-site-package']
+        virtualenv.main()
+        execute([python_path] + args)
+        sys.exit(0)
+
+
+if options.profile:
+    if not os.path.isfile(options.profile):
+        sys.stderr.write('No such profile file: %s\n' % options.profile)
+        sys.exit(1)
 
-    print "Creating configuration '%s'" % os.path.abspath('buildout.cfg')
-    config = open('buildout.cfg', 'w')
+    print "Creating configuration '%s'" % os.path.abspath(options.config)
+    config = open(options.config, 'w')
     config.write("""[buildout]
 extends = %s
-""" % buildout_config)
-    del config
+""" % options.profile)
+    config.close()
 
-    sys.argv.remove('--buildout-profile')
-    sys.argv.remove(buildout_config)
 
+install('zc.buildout==%s' % options.buildout_version)
+import zc.buildout.buildout
+zc.buildout.buildout.main(['-c', options.config, 'bootstrap'])
 
-if sys.platform.startswith('win'):
-    bin_dir = 'Scripts'
-else:
-    bin_dir = 'bin'
-python_path = os.path.join(bin_dir, os.path.basename(sys.executable))
 
-try:
-    import pkg_resources
-except ImportError:
-    ez = {}
-    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
-
-cmd = 'from setuptools.command.easy_install import main; main()'
-if sys.platform == 'win32':
-    cmd = '"%s"' % cmd # work around spawn lamosity on windows
-
-ws = pkg_resources.working_set
-assert os.spawnle(
-    os.P_WAIT, sys.executable, sys.executable,
-    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout', 'virtualenv==1.5.1',
-    dict(os.environ,
-         PYTHONPATH=
-         ws.find(pkg_resources.Requirement.parse('setuptools')).location
-         ),
-    ) == 0
-
-ws.add_entry(tmpeggs)
-if enable_virtualenv and not os.path.isfile(python_path):
-    ws.require('virtualenv')
-    import virtualenv
-    from subprocess import call
-    args = sys.argv[:]
-    sys.argv = [sys.argv[0], os.getcwd(), '--clear', '--no-site-package']
-    virtualenv.main()
-    call(python_path + ' ' + ' '.join(args), shell=True)
-    sys.exit(0)
-    print 'exit'
+if options.install:
+    print "Start installation ..."
+    # Run install
+    execute(
+        [sys.executable, quote(os.path.join(bin_dir, 'buildout')),
+         '-c', options.config, 'install'])
 
-ws.require('zc.buildout')
-import zc.buildout.buildout
-zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
-shutil.rmtree(tmpeggs)
+sys.exit(0)

Modified: buildout/silva/branch/Silva-2.1/profiles/base.cfg
==============================================================================
--- buildout/silva/branch/Silva-2.1/profiles/base.cfg	(original)
+++ buildout/silva/branch/Silva-2.1/profiles/base.cfg	Tue Feb 18 10:27:49 2014
@@ -1,15 +1,12 @@
 [buildout]
+unzip = true
 parts =
     zope2
     silva-all
     instance
 
-find-links =
-    http://infrae.com/download/simple/
-    https://dist.infrae.com/thirdparty/
-    http://download.zope.org/ppix/
-    http://download.zope.org/distribution/
-
+find-links = https://dist.infrae.com/thirdparty
+allow-hosts =
 extensions = buildout.dumppickedversions
 versions = versions
 
@@ -20,12 +17,13 @@
 collective.monkeypatcher = 1.0b2
 infrae.subversion = 1.4.5
 lxml = 2.2.4
+mr.developer = 1.22-infrae1
 plone.recipe.zope2install = 3.2
 plone.recipe.zope2instance = 3.6
 py = 1.1.0
-setuptools = 0.6c11
+setuptools = 1.4.2
 silva.export.opendocument = 1.0
-zc.buildout = 1.4.2
+zc.buildout = 1.4.4
 zc.recipe.egg = 1.2.2
 zope.component = 3.5.1
 zope.contenttype = 3.4.2
@@ -54,7 +52,7 @@
     ${silva-all:base}/SilvaMailing/tag/SilvaMailing-0.5.2 SilvaMailing
     ${silva-all:base}/SilvaMetadata/tag/SilvaMetadata-1.2 SilvaMetadata
     ${silva-all:base}/SilvaPoll/tag/SilvaPoll-1.3.1 SilvaPoll
-    ${silva-all:base}/SilvaNews/tag/SilvaNewsNetwork-2.7.10 SilvaNews
+    ${silva-all:base}/SilvaNews/tag/SilvaNewsNetwork-2.7.11 SilvaNews
     ${silva-all:base}/SilvaViews/tag/SilvaViews-0.14 SilvaViews
     ${silva-all:base}/Sprout/tag/Sprout-0.9 Sprout
     ${silva-all:base}/XMLWidgets/tag/XMLWidgets-0_13 XMLWidgets
@@ -84,7 +82,7 @@
     ${buildout:directory}/products
     ${silva-all:location}
 eggs =
-    PILwoTK
+    PILwoTk
     lxml
     silva.export.opendocument
     zope.contenttype