16
16
Simply run this script in a directory containing a buildout.cfg.
17
17
The script accepts buildout command-line options, so you can
18
18
use the -c option to specify an alternate configuration file.
21
import os, shutil, sys, tempfile
22
from optparse import OptionParser
23
import os, shutil, sys, tempfile, urllib2
24
25
tmpeggs = tempfile.mkdtemp()
27
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
29
Bootstraps a buildout-based project.
31
Simply run this script in a directory containing a buildout.cfg, using the
32
Python that you want bin/buildout to use.
34
Note that by using --setup-source and --download-base to point to
35
local resources, you can keep this script from going over the network.
38
parser = OptionParser(usage=usage)
39
parser.add_option("-v", "--version", help="use a specific zc.buildout version")
41
parser.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."))
50
parser.add_option("-c", "--config-file",
51
help=("Specify the path to the buildout configuration "
53
parser.add_option("-f", "--find-links",
54
help=("Specify a URL to search for buildout releases"))
57
options, args = parser.parse_args()
59
######################################################################
60
# load/install distribute
27
is_jython = sys.platform.startswith('java')
64
import pkg_resources, setuptools
65
if not hasattr(pkg_resources, '_distribute'):
68
31
except ImportError:
72
from urllib.request import urlopen
74
from urllib2 import urlopen
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)
33
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
35
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
82
37
import pkg_resources
83
# This does not (always?) update the default working set. We will
86
if path not in pkg_resources.working_set.entries:
87
pkg_resources.working_set.add_entry(path)
89
######################################################################
39
if sys.platform == 'win32':
42
return '"%s"' % c # work around spawn lamosity on windows
49
cmd = 'from setuptools.command.easy_install import main; main()'
92
50
ws = pkg_resources.working_set
94
cmd = [sys.executable, '-c',
95
'from setuptools.command.easy_install import main; main()',
98
find_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)
105
cmd.extend(['-f', find_links])
107
distribute_path = ws.find(
108
pkg_resources.Requirement.parse('distribute')).location
110
requirement = 'zc.buildout'
111
version = options.version
112
if 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):
121
index = setuptools.package_index.PackageIndex(
122
search_path=[distribute_path])
124
index.add_find_links((find_links,))
125
req = pkg_resources.Requirement.parse(requirement)
126
if index.obtain(req) is not 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:
139
version = best[-1].version
141
requirement = '=='.join((requirement, version))
142
cmd.append(requirement)
145
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
147
"Failed to execute command:\n%s",
150
######################################################################
151
# Import and run buildout
55
assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
56
quote(tmpeggs), 'zc.buildout'],
59
ws.find(pkg_resources.Requirement.parse('setuptools')).location
65
os.P_WAIT, sys.executable, quote (sys.executable),
66
'-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
69
ws.find(pkg_resources.Requirement.parse('setuptools')).location
153
73
ws.add_entry(tmpeggs)
154
ws.require(requirement)
74
ws.require('zc.buildout')
155
75
import zc.buildout.buildout
157
if not [a for a in args if '=' not in a]:
158
args.append('bootstrap')
160
# if -c was provided, we push it back into args for buildout' main function
161
if options.config_file is not None:
162
args[0:0] = ['-c', options.config_file]
164
zc.buildout.buildout.main(args)
76
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
165
77
shutil.rmtree(tmpeggs)