1
##############################################################################
3
# Copyright (c) 2006 Zope Corporation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
13
##############################################################################
14
"""Bootstrap a buildout-based project
16
Simply run this script in a directory containing a buildout.cfg.
17
The script accepts buildout command-line options, so you can
18
use the -c option to specify an alternate configuration file.
21
import os, shutil, sys, tempfile, urllib2
24
py_version = 'python%s.%s' % (sys.version_info[0], sys.version_info[1])
27
if not os.path.exists(path):
28
print 'Creating %s' % path
31
def symlink(src, dest):
32
if not os.path.exists(dest):
35
print 'Symlink %s already exists' % dest
39
if os.path.exists(dir):
40
print 'Deleting tree %s' % dir
44
if os.name == 'posix':
45
oldmode = os.stat(fn).st_mode & 07777
46
newmode = (oldmode | 0555) & 07777
49
def make_virtual_python():
50
if os.name != 'posix':
51
print "This script only works on Unix-like platforms, sorry."
54
lib_dir = join('python', 'lib', py_version)
55
inc_dir = join('python', 'include', py_version)
56
bin_dir = join('python', 'bin')
58
if sys.executable.startswith(bin_dir):
59
print 'Please use the *system* python to run this script'
65
stdlib_dir = join(prefix, 'lib', py_version)
66
for fn in os.listdir(stdlib_dir):
67
if fn != 'site-packages':
68
symlink(join(stdlib_dir, fn), join(lib_dir, fn))
70
mkdir(join(lib_dir, 'site-packages'))
73
stdinc_dir = join(prefix, 'include', py_version)
74
for fn in os.listdir(stdinc_dir):
75
symlink(join(stdinc_dir, fn), join(inc_dir, fn))
77
if sys.exec_prefix != sys.prefix:
78
exec_dir = join(sys.exec_prefix, 'lib', py_version)
79
for fn in os.listdir(exec_dir):
80
symlink(join(exec_dir, fn), join(lib_dir, fn))
83
print 'Copying %s to %s' % (sys.executable, bin_dir)
84
py_executable = join(bin_dir, 'python')
85
if sys.executable != py_executable:
86
shutil.copyfile(sys.executable, py_executable)
87
make_exe(py_executable)
90
if __name__ == "__main__":
91
if sys.executable != os.path.abspath('python/bin/python'):
94
os.P_WAIT, 'python/bin/python',
95
['python/bin/python'] + sys.argv, os.environ))
97
tmpeggs = tempfile.mkdtemp()
100
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
102
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
106
cmd = 'from setuptools.command.easy_install import main; main()'
107
if sys.platform == 'win32':
108
cmd = '"%s"' % cmd # work around spawn lamosity on windows
110
ws = pkg_resources.working_set
112
os.P_WAIT, sys.executable, sys.executable,
113
'-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
116
ws.find(pkg_resources.Requirement.parse('setuptools')).location
120
ws.add_entry(tmpeggs)
121
ws.require('zc.buildout')
122
import zc.buildout.buildout
123
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
124
shutil.rmtree(tmpeggs)