0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 ##############################################################################
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 #
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 # Copyright (c) 2006 Zope Corporation and Contributors.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 # All Rights Reserved.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 #
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 # This software is subject to the provisions of the Zope Public License,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 # FOR A PARTICULAR PURPOSE.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 #
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 ##############################################################################
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 """Bootstrap a buildout-based project
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 Simply run this script in a directory containing a buildout.cfg.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 The script accepts buildout command-line options, so you can
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 use the -c option to specify an alternate configuration file.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 $Id: bootstrap.py 105417 2009-11-01 15:15:20Z tarek $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 """
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 import os, shutil, sys, tempfile, urllib2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 from optparse import OptionParser
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 tmpeggs = tempfile.mkdtemp()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 is_jython = sys.platform.startswith('java')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 # parsing arguments
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 parser = OptionParser()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 parser.add_option("-v", "--version", dest="version",
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 help="use a specific zc.buildout version")
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 parser.add_option("-d", "--distribute",
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 action="store_true", dest="distribute", default=False,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 help="Use Disribute rather than Setuptools.")
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 parser.add_option("-c", None, action="store", dest="config_file",
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 help=("Specify the path to the buildout configuration "
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 "file to be used."))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 options, args = parser.parse_args()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 # if -c was provided, we push it back into args for buildout' main function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 if options.config_file is not None:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 args += ['-c', options.config_file]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 if options.version is not None:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 VERSION = '==%s' % options.version
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 else:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 VERSION = ''
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 USE_DISTRIBUTE = options.distribute
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 args = args + ['bootstrap']
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 to_reload = False
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 try:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 import pkg_resources
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 if not hasattr(pkg_resources, '_distribute'):
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 to_reload = True
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 raise ImportError
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 except ImportError:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 ez = {}
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 if USE_DISTRIBUTE:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 ).read() in ez
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 else:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 ).read() in ez
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 if to_reload:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 reload(pkg_resources)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 else:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 import pkg_resources
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 if sys.platform == 'win32':
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 def quote(c):
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 if ' ' in c:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 return '"%s"' % c # work around spawn lamosity on windows
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 else:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 return c
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 else:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 def quote (c):
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 return c
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 cmd = 'from setuptools.command.easy_install import main; main()'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 ws = pkg_resources.working_set
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 if USE_DISTRIBUTE:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 requirement = 'distribute'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 else:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 requirement = 'setuptools'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 if is_jython:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 import subprocess
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 quote(tmpeggs), 'zc.buildout' + VERSION],
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 env=dict(os.environ,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 PYTHONPATH=
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 ws.find(pkg_resources.Requirement.parse(requirement)).location
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 ),
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 ).wait() == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 else:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 assert os.spawnle(
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 os.P_WAIT, sys.executable, quote (sys.executable),
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 dict(os.environ,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 PYTHONPATH=
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 ws.find(pkg_resources.Requirement.parse(requirement)).location
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 ),
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 ) == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 ws.add_entry(tmpeggs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 ws.require('zc.buildout' + VERSION)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 import zc.buildout.buildout
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 zc.buildout.buildout.main(args)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 shutil.rmtree(tmpeggs)
|