source: products/quintagroup.plonecomments/buildouts/plone-3.0/bootstrap.py

Last change on this file was 2178, checked in by crchemist, 14 years ago

initial import

File size: 3.8 KB
Line 
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
16Simply run this script in a directory containing a buildout.cfg.
17The script accepts buildout command-line options, so you can
18use the -c option to specify an alternate configuration file.
19"""
20
21import os, shutil, sys, tempfile, urllib2
22from optparse import OptionParser
23
24tmpeggs = tempfile.mkdtemp()
25
26is_jython = sys.platform.startswith('java')
27
28# parsing arguments
29parser = OptionParser()
30parser.add_option("-v", "--version", dest="version",
31                          help="use a specific zc.buildout version")
32parser.add_option("-d", "--distribute",
33                   action="store_true", dest="distribute", default=False,
34                   help="Use Disribute rather than Setuptools.")
35
36parser.add_option("-c", None, action="store", dest="config_file",
37                   help=("Specify the path to the buildout configuration "
38                         "file to be used."))
39
40options, args = parser.parse_args()
41
42# if -c was provided, we push it back into args for buildout' main function
43if options.config_file is not None:
44    args += ['-c', options.config_file]
45
46if options.version is not None:
47    VERSION = '==%s' % options.version
48else:
49    VERSION = ''
50
51# We decided to always use distribute, make sure this is the default for us
52# USE_DISTRIBUTE = options.distribute
53USE_DISTRIBUTE = True
54args = args + ['bootstrap']
55
56to_reload = False
57try:
58    import pkg_resources
59    if not hasattr(pkg_resources, '_distribute'):
60        to_reload = True
61        raise ImportError
62except ImportError:
63    ez = {}
64    if USE_DISTRIBUTE:
65        exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
66                         ).read() in ez
67        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
68    else:
69        exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
70                             ).read() in ez
71        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
72
73    if to_reload:
74        reload(pkg_resources)
75    else:
76        import pkg_resources
77
78if sys.platform == 'win32':
79    def quote(c):
80        if ' ' in c:
81            return '"%s"' % c # work around spawn lamosity on windows
82        else:
83            return c
84else:
85    def quote (c):
86        return c
87
88cmd = 'from setuptools.command.easy_install import main; main()'
89ws  = pkg_resources.working_set
90
91if USE_DISTRIBUTE:
92    requirement = 'distribute'
93else:
94    requirement = 'setuptools'
95
96if is_jython:
97    import subprocess
98
99    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
100           quote(tmpeggs), 'zc.buildout' + VERSION],
101           env=dict(os.environ,
102               PYTHONPATH=
103               ws.find(pkg_resources.Requirement.parse(requirement)).location
104               ),
105           ).wait() == 0
106
107else:
108    assert os.spawnle(
109        os.P_WAIT, sys.executable, quote (sys.executable),
110        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
111        dict(os.environ,
112            PYTHONPATH=
113            ws.find(pkg_resources.Requirement.parse(requirement)).location
114            ),
115        ) == 0
116
117ws.add_entry(tmpeggs)
118ws.require('zc.buildout' + VERSION)
119import zc.buildout.buildout
120zc.buildout.buildout.main(args)
121shutil.rmtree(tmpeggs)
Note: See TracBrowser for help on using the repository browser.