source: main/waeup.plonetheme/trunk/bootstrap.py @ 13599

Last change on this file since 13599 was 10867, checked in by Henrik Bettermann, 11 years ago

Upgrade waeup plone theme to Plone 4.2.4.

Use buildout for installation.

  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1##############################################################################
2#
3# Copyright (c) 2006 Zope Foundation and Contributors.
4# All Rights Reserved.
5#
6# This software is subject to the provisions of the Zope Public License,
7# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11# FOR A PARTICULAR PURPOSE.
12#
13##############################################################################
14"""Bootstrap a buildout-based project
15
16Simply run this script in a directory containing a buildout.cfg.
17The script accepts buildout command-line options, so you can
18use the -c option to specify an alternate configuration file.
19"""
20
21import os, shutil, sys, tempfile
22from optparse import OptionParser
23
24tmpeggs = tempfile.mkdtemp()
25
26usage = '''\
27[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
28
29Bootstraps a buildout-based project.
30
31Simply run this script in a directory containing a buildout.cfg, using the
32Python that you want bin/buildout to use.
33
34Note that by using --setup-source and --download-base to point to
35local resources, you can keep this script from going over the network.
36'''
37
38parser = OptionParser(usage=usage)
39parser.add_option("-v", "--version", help="use a specific zc.buildout version")
40
41parser.add_option("-t", "--accept-buildout-test-releases",
42                  dest='accept_buildout_test_releases',
43                  action="store_true", default=False,
44                  help=("Normally, if you do not specify a --version, the "
45                        "bootstrap script and buildout gets the newest "
46                        "*final* versions of zc.buildout and its recipes and "
47                        "extensions for you.  If you use this flag, "
48                        "bootstrap and buildout will get the newest releases "
49                        "even if they are alphas or betas."))
50parser.add_option("-c", "--config-file",
51                   help=("Specify the path to the buildout configuration "
52                         "file to be used."))
53parser.add_option("-f", "--find-links",
54                   help=("Specify a URL to search for buildout releases"))
55
56
57options, args = parser.parse_args()
58
59######################################################################
60# load/install distribute
61
62to_reload = False
63try:
64    import pkg_resources, setuptools
65    if not hasattr(pkg_resources, '_distribute'):
66        to_reload = True
67        raise ImportError
68except ImportError:
69    ez = {}
70
71    try:
72        from urllib.request import urlopen
73    except ImportError:
74        from urllib2 import urlopen
75
76    exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
77    setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
78    ez['use_setuptools'](**setup_args)
79
80    if to_reload:
81        reload(pkg_resources)
82    import pkg_resources
83    # This does not (always?) update the default working set.  We will
84    # do it.
85    for path in sys.path:
86        if path not in pkg_resources.working_set.entries:
87            pkg_resources.working_set.add_entry(path)
88
89######################################################################
90# Install buildout
91
92ws  = pkg_resources.working_set
93
94cmd = [sys.executable, '-c',
95       'from setuptools.command.easy_install import main; main()',
96       '-mZqNxd', tmpeggs]
97
98find_links = os.environ.get(
99    'bootstrap-testing-find-links',
100    options.find_links or
101    ('http://downloads.buildout.org/'
102     if options.accept_buildout_test_releases else None)
103    )
104if find_links:
105    cmd.extend(['-f', find_links])
106
107distribute_path = ws.find(
108    pkg_resources.Requirement.parse('distribute')).location
109
110requirement = 'zc.buildout'
111version = options.version
112if version is None and not options.accept_buildout_test_releases:
113    # Figure out the most recent final version of zc.buildout.
114    import setuptools.package_index
115    _final_parts = '*final-', '*final'
116    def _final_version(parsed_version):
117        for part in parsed_version:
118            if (part[:1] == '*') and (part not in _final_parts):
119                return False
120        return True
121    index = setuptools.package_index.PackageIndex(
122        search_path=[distribute_path])
123    if find_links:
124        index.add_find_links((find_links,))
125    req = pkg_resources.Requirement.parse(requirement)
126    if index.obtain(req) is not None:
127        best = []
128        bestv = None
129        for dist in index[req.project_name]:
130            distv = dist.parsed_version
131            if _final_version(distv):
132                if bestv is None or distv > bestv:
133                    best = [dist]
134                    bestv = distv
135                elif distv == bestv:
136                    best.append(dist)
137        if best:
138            best.sort()
139            version = best[-1].version
140if version:
141    requirement = '=='.join((requirement, version))
142cmd.append(requirement)
143
144import subprocess
145if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
146    raise Exception(
147        "Failed to execute command:\n%s",
148        repr(cmd)[1:-1])
149
150######################################################################
151# Import and run buildout
152
153ws.add_entry(tmpeggs)
154ws.require(requirement)
155import zc.buildout.buildout
156
157if not [a for a in args if '=' not in a]:
158    args.append('bootstrap')
159
160# if -c was provided, we push it back into args for buildout' main function
161if options.config_file is not None:
162    args[0:0] = ['-c', options.config_file]
163
164zc.buildout.buildout.main(args)
165shutil.rmtree(tmpeggs)
Note: See TracBrowser for help on using the repository browser.