|
| 1 | +############################################################################## |
| 2 | +# |
| 3 | +# Copyright (c) 2006 Zope Corporation and Contributors. |
| 4 | +# All Rights Reserved. |
| 5 | +# |
| 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. |
| 12 | +# |
| 13 | +############################################################################## |
| 14 | +"""Bootstrap a buildout-based project |
| 15 | +
|
| 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. |
| 19 | +
|
| 20 | +$Id: bootstrap.py 102545 2009-08-06 14:49:47Z chrisw $ |
| 21 | +""" |
| 22 | + |
| 23 | +import os, shutil, sys, tempfile, urllib2 |
| 24 | +from optparse import OptionParser |
| 25 | + |
| 26 | +tmpeggs = tempfile.mkdtemp() |
| 27 | + |
| 28 | +is_jython = sys.platform.startswith('java') |
| 29 | + |
| 30 | +# parsing arguments |
| 31 | +parser = OptionParser() |
| 32 | +parser.add_option("-v", "--version", dest="version", |
| 33 | + help="use a specific zc.buildout version") |
| 34 | +parser.add_option("-d", "--distribute", |
| 35 | + action="store_true", dest="distribute", default=True, |
| 36 | + help="Use Disribute rather than Setuptools.") |
| 37 | + |
| 38 | +options, args = parser.parse_args() |
| 39 | + |
| 40 | +if options.version is not None: |
| 41 | + VERSION = '==%s' % options.version |
| 42 | +else: |
| 43 | + VERSION = '' |
| 44 | + |
| 45 | +USE_DISTRIBUTE = options.distribute |
| 46 | +args = args + ['bootstrap'] |
| 47 | + |
| 48 | +to_reload = False |
| 49 | +try: |
| 50 | + import pkg_resources |
| 51 | + if not hasattr(pkg_resources, '_distribute'): |
| 52 | + to_reload = True |
| 53 | + raise ImportError |
| 54 | +except ImportError: |
| 55 | + ez = {} |
| 56 | + if USE_DISTRIBUTE: |
| 57 | + exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py' |
| 58 | + ).read() in ez |
| 59 | + ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True) |
| 60 | + else: |
| 61 | + exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py' |
| 62 | + ).read() in ez |
| 63 | + ez['use_setuptools'](to_dir=tmpeggs, download_delay=0) |
| 64 | + |
| 65 | + if to_reload: |
| 66 | + reload(pkg_resources) |
| 67 | + else: |
| 68 | + import pkg_resources |
| 69 | + |
| 70 | +if sys.platform == 'win32': |
| 71 | + def quote(c): |
| 72 | + if ' ' in c: |
| 73 | + return '"%s"' % c # work around spawn lamosity on windows |
| 74 | + else: |
| 75 | + return c |
| 76 | +else: |
| 77 | + def quote (c): |
| 78 | + return c |
| 79 | + |
| 80 | +cmd = 'from setuptools.command.easy_install import main; main()' |
| 81 | +ws = pkg_resources.working_set |
| 82 | + |
| 83 | +if USE_DISTRIBUTE: |
| 84 | + requirement = 'distribute' |
| 85 | +else: |
| 86 | + requirement = 'setuptools' |
| 87 | + |
| 88 | +if is_jython: |
| 89 | + import subprocess |
| 90 | + |
| 91 | + assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd', |
| 92 | + quote(tmpeggs), 'zc.buildout' + VERSION], |
| 93 | + env=dict(os.environ, |
| 94 | + PYTHONPATH= |
| 95 | + ws.find(pkg_resources.Requirement.parse(requirement)).location |
| 96 | + ), |
| 97 | + ).wait() == 0 |
| 98 | + |
| 99 | +else: |
| 100 | + assert os.spawnle( |
| 101 | + os.P_WAIT, sys.executable, quote (sys.executable), |
| 102 | + '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION, |
| 103 | + dict(os.environ, |
| 104 | + PYTHONPATH= |
| 105 | + ws.find(pkg_resources.Requirement.parse(requirement)).location |
| 106 | + ), |
| 107 | + ) == 0 |
| 108 | + |
| 109 | +ws.add_entry(tmpeggs) |
| 110 | +ws.require('zc.buildout' + VERSION) |
| 111 | +import zc.buildout.buildout |
| 112 | +zc.buildout.buildout.main(args) |
| 113 | +shutil.rmtree(tmpeggs) |
0 commit comments