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 101778 2009-07-10 00:55:19Z 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)=(\S*)' % ('|'.join(configuration),)).match
61
if args == ['--help']:
70
if val in configuration:
72
if not args or args[0].startswith('-'):
73
print "ERROR: %s requires an argument."
76
configuration[val] = args[0]
78
match = match_equals(val)
79
if match and match.group(1) in configuration:
80
configuration[match.group(1)] = match.group(2)
85
for name in ('--ez_setup-source', '--download-base'):
86
val = configuration[name]
87
if val is not None and '://' not in val: # we're being lazy.
88
configuration[name] = 'file://%s' % (
89
urllib.pathname2url(os.path.abspath(os.path.expanduser(val))),)
91
if (configuration['--download-base'] and
92
not configuration['--download-base'].endswith('/')):
93
# download base needs a trailing slash to make the world happy
94
configuration['--download-base'] += '/'
96
if not configuration['--eggs']:
97
configuration['--eggs'] = tmpeggs = tempfile.mkdtemp()
99
configuration['--eggs'] = os.path.abspath(
100
os.path.expanduser(configuration['--eggs']))
102
if configuration['--version']:
103
configuration['--version'] = '==' + configuration['--version']
35
106
import pkg_resources
36
107
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(),),
109
exec urllib2.urlopen(configuration['--ez_setup-source']).read() in ez
110
setuptools_args = dict(to_dir=configuration['--eggs'], download_delay=0)
111
if configuration['--download-base']:
112
setuptools_args['download_base'] = configuration['--download-base']
113
ez['use_setuptools'](**setuptools_args)
50
115
import pkg_resources
62
cmd = 'from setuptools.command.easy_install import main; main()'
63
ws = pkg_resources.working_set
126
cmd = [quote(sys.executable),
128
quote('from setuptools.command.easy_install import main; main()'),
130
quote(configuration['--eggs'])]
132
if configuration['--download-base']:
133
cmd.extend(['-f', quote(configuration['--download-base'])])
135
cmd.append('zc.buildout' + configuration['--version'])
137
ws = pkg_resources.working_set
140
PYTHONPATH=ws.find(pkg_resources.Requirement.parse('setuptools')).location)
68
assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
69
quote(tmpeggs), 'zc.buildout'],
72
ws.find(pkg_resources.Requirement.parse('setuptools')).location
145
exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
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
147
# Jython can use subprocess but not spawn. We prefer it generally.
148
exitcode = subprocess.Popen(cmd, env=env).wait()
150
# we shouldn't need an error message because a failure
151
# should have generated a visible traceback in the subprocess.
87
ws.require('zc.buildout')
154
ws.add_entry(configuration['--eggs'])
155
ws.require('zc.buildout' + configuration['--version'])
88
156
import zc.buildout.buildout
89
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
90
shutil.rmtree(tmpeggs)
157
args.append('bootstrap')
158
zc.buildout.buildout.main(args)
159
if tmpeggs is not None:
160
shutil.rmtree(tmpeggs)