1
1
##############################################################################
3
# Copyright (c) 2006 Zope Corporation and Contributors.
3
# Copyright (c) 2006 Zope Foundation and Contributors.
4
4
# All Rights Reserved.
6
6
# This software is subject to the provisions of the Zope Public License,
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.
23
import os, shutil, sys, tempfile, textwrap, urllib, urllib2
21
import os, shutil, sys, tempfile, textwrap, urllib, urllib2, subprocess
24
22
from optparse import OptionParser
26
24
if sys.platform == 'win32':
33
# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
34
stdout, stderr = subprocess.Popen(
35
[sys.executable, '-Sc',
37
' import ConfigParser\n'
38
'except ImportError:\n'
42
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
43
has_broken_dash_S = bool(int(stdout.strip()))
35
45
# In order to be more robust in the face of system Pythons, we want to
36
46
# run without site-packages loaded. This is somewhat tricky, in
37
47
# particular because Python 2.6's distutils imports site, so starting
38
48
# with the -S flag is not sufficient. However, we'll start with that:
39
if 'site' in sys.modules:
49
if not has_broken_dash_S and 'site' in sys.modules:
40
50
# We will restart with python -S.
42
52
args[0:0] = [sys.executable, '-S']
109
119
help=("Specify a directory for storing eggs. Defaults to "
110
120
"a temporary directory that is deleted when the "
111
121
"bootstrap script completes."))
122
parser.add_option("-t", "--accept-buildout-test-releases",
123
dest='accept_buildout_test_releases',
124
action="store_true", default=False,
125
help=("Normally, if you do not specify a --version, the "
126
"bootstrap script and buildout gets the newest "
127
"*final* versions of zc.buildout and its recipes and "
128
"extensions for you. If you use this flag, "
129
"bootstrap and buildout will get the newest releases "
130
"even if they are alphas or betas."))
112
131
parser.add_option("-c", None, action="store", dest="config_file",
113
132
help=("Specify the path to the buildout configuration "
114
133
"file to be used."))
116
135
options, args = parser.parse_args()
118
# if -c was provided, we push it back into args for buildout' main function
137
# if -c was provided, we push it back into args for buildout's main function
119
138
if options.config_file is not None:
120
139
args += ['-c', options.config_file]
131
150
options.setup_source = setuptools_source
133
args = args + ['bootstrap']
152
if options.accept_buildout_test_releases:
153
args.append('buildout:accept-buildout-test-releases=true')
154
args.append('bootstrap')
138
157
import pkg_resources
158
import setuptools # A flag. Sometimes pkg_resources is installed alone.
140
159
if not hasattr(pkg_resources, '_distribute'):
141
160
raise ImportError
142
import setuptools # A flag. Sometimes pkg_resources is installed alone.
143
161
except ImportError:
144
162
ez_code = urllib2.urlopen(
145
163
options.setup_source).read().replace('\r\n', '\n')
151
169
if options.use_distribute:
152
170
setup_args['no_fake'] = True
153
171
ez['use_setuptools'](**setup_args)
155
reload(pkg_resources)
172
reload(sys.modules['pkg_resources'])
158
174
# This does not (always?) update the default working set. We will
160
176
for path in sys.path:
170
if options.download_base:
171
cmd.extend(['-f', quote(options.download_base)])
186
if not has_broken_dash_S:
173
requirement = 'zc.buildout'
175
requirement = '=='.join((requirement, options.version))
176
cmd.append(requirement)
189
find_links = options.download_base
191
find_links = os.environ.get('bootstrap-testing-find-links')
193
cmd.extend(['-f', quote(find_links)])
178
195
if options.use_distribute:
179
196
setup_requirement = 'distribute'
181
198
setup_requirement = 'setuptools'
182
199
ws = pkg_resources.working_set
200
setup_requirement_path = ws.find(
201
pkg_resources.Requirement.parse(setup_requirement)).location
186
pkg_resources.Requirement.parse(setup_requirement)).location)
204
PYTHONPATH=setup_requirement_path)
206
requirement = 'zc.buildout'
207
version = options.version
208
if version is None and not options.accept_buildout_test_releases:
209
# Figure out the most recent final version of zc.buildout.
210
import setuptools.package_index
211
_final_parts = '*final-', '*final'
212
def _final_version(parsed_version):
213
for part in parsed_version:
214
if (part[:1] == '*') and (part not in _final_parts):
217
index = setuptools.package_index.PackageIndex(
218
search_path=[setup_requirement_path])
220
index.add_find_links((find_links,))
221
req = pkg_resources.Requirement.parse(requirement)
222
if index.obtain(req) is not None:
225
for dist in index[req.project_name]:
226
distv = dist.parsed_version
227
if _final_version(distv):
228
if bestv is None or distv > bestv:
235
version = best[-1].version
237
requirement = '=='.join((requirement, version))
238
cmd.append(requirement)
189
241
import subprocess