11
11
# FOR A PARTICULAR PURPOSE.
13
13
##############################################################################
15
# NOTE TO LAUNCHPAD DEVELOPERS: This is a bootstrapping file from the
16
# zc.buildout project, which we have hacked slightly: look for the string
17
# "HACK" below. See the docstring below for usage.
19
14
"""Bootstrap a buildout-based project
21
16
Simply run this script in a directory containing a buildout.cfg.
22
17
The script accepts buildout command-line options, so you can
23
18
use the -c option to specify an alternate configuration file.
20
$Id: bootstrap.py 101879 2009-07-14 01:24:48Z gary $
28
import os, shutil, sys, tempfile, urllib2
30
tmpeggs = tempfile.mkdtemp()
32
is_jython = sys.platform.startswith('java')
23
import os, re, shutil, sys, tempfile, textwrap, urllib, urllib2
25
# We have to manually parse our options rather than using one of the stdlib
26
# tools because we want to pass the ones we don't recognize along to
27
# zc.buildout.buildout.main.
30
'--ez_setup-source': 'http://peak.telecommunity.com/dist/ez_setup.py',
32
'--download-base': None,
35
helpstring = __doc__ + textwrap.dedent('''
36
This script recognizes the following options itself. The first option it
37
encounters that is not one of these will cause the script to stop parsing
38
options and pass the rest on to buildout. Therefore, if you want to use
39
any of the following options *and* buildout command-line options like
40
-c, first use the following options, and then use the buildout options.
43
--version=ZC_BUILDOUT_VERSION
44
Specify a version number of the zc.buildout to use
45
--ez_setup-source=URL_OR_FILE
46
Specify a URL or file location for the ez_setup file.
49
--download-base=URL_OR_DIRECTORY
50
Specify a URL or directory for downloading setuptools and
51
zc.buildout. Defaults to PyPI.
53
Specify a directory for storing eggs. Defaults to a temporary
54
directory that is deleted when the bootstrap script completes.
56
By using --ez_setup-source and --download-base to point to local resources,
57
you can keep this script from going over the network.
59
match_equals = re.compile(r'(%s)=(.*)' % ('|'.join(configuration),)).match
61
if args == ['--help']:
65
# If we end up using a temporary directory for storing our eggs, this will
66
# hold the path of that directory. On the other hand, if an explicit directory
67
# is specified in the argv, this will remain None.
72
if val in configuration:
74
if not args or args[0].startswith('-'):
75
print "ERROR: %s requires an argument."
78
configuration[val] = args[0]
80
match = match_equals(val)
81
if match and match.group(1) in configuration:
82
configuration[match.group(1)] = match.group(2)
87
for name in ('--ez_setup-source', '--download-base'):
88
val = configuration[name]
89
if val is not None and '://' not in val: # We're being lazy.
90
configuration[name] = 'file://%s' % (
91
urllib.pathname2url(os.path.abspath(os.path.expanduser(val))),)
93
if (configuration['--download-base'] and
94
not configuration['--download-base'].endswith('/')):
95
# Download base needs a trailing slash to make the world happy.
96
configuration['--download-base'] += '/'
98
if not configuration['--eggs']:
99
configuration['--eggs'] = tmpeggs = tempfile.mkdtemp()
101
configuration['--eggs'] = os.path.abspath(
102
os.path.expanduser(configuration['--eggs']))
104
# The requirement is what we will pass to setuptools to specify zc.buildout.
105
requirement = 'zc.buildout'
106
if configuration['--version']:
107
requirement += '==' + configuration['--version']
35
110
import pkg_resources
36
111
except ImportError:
38
# HACK: the next two logical lines have been hacked for Launchpad to make
39
# bootstrapping not get any files over the network. This is useful for
40
# development because it speeds up the build and makes it possible to
41
# make a new branch when you don't have network access. It is essential
42
# for deployment because we currently do not allow network access on PQM
43
# or our deployment boxes.
44
exec open('ez_setup.py').read() in ez
47
download_base='file://%s/download-cache/dist/' % (os.getcwd(),),
113
exec urllib2.urlopen(configuration['--ez_setup-source']).read() in ez
114
setuptools_args = dict(to_dir=configuration['--eggs'], download_delay=0)
115
if configuration['--download-base']:
116
setuptools_args['download_base'] = configuration['--download-base']
117
ez['use_setuptools'](**setuptools_args)
50
119
import pkg_resources
62
cmd = 'from setuptools.command.easy_install import main; main()'
63
ws = pkg_resources.working_set
130
cmd = [quote(sys.executable),
132
quote('from setuptools.command.easy_install import main; main()'),
134
quote(configuration['--eggs'])]
136
if configuration['--download-base']:
137
cmd.extend(['-f', quote(configuration['--download-base'])])
139
cmd.append(requirement)
141
ws = pkg_resources.working_set
144
PYTHONPATH=ws.find(pkg_resources.Requirement.parse('setuptools')).location)
146
is_jython = sys.platform.startswith('java')
68
assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
69
quote(tmpeggs), 'zc.buildout'],
72
ws.find(pkg_resources.Requirement.parse('setuptools')).location
78
os.P_WAIT, sys.executable, quote (sys.executable),
79
'-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
82
ws.find(pkg_resources.Requirement.parse('setuptools')).location
87
ws.require('zc.buildout')
149
exitcode = subprocess.Popen(cmd, env=env).wait()
150
else: # Windows needs this, apparently; otherwise we would prefer subprocess
151
exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
154
print ("An error occured when trying to install zc.buildout. "
155
"Look above this message for any errors that "
156
"were output by easy_install.")
159
ws.add_entry(configuration['--eggs'])
160
ws.require(requirement)
88
161
import zc.buildout.buildout
89
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
90
shutil.rmtree(tmpeggs)
162
args.append('bootstrap')
163
zc.buildout.buildout.main(args)
164
if tmpeggs is not None:
165
shutil.rmtree(tmpeggs)