bootstrap.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Fri, 14 Jan 2011 01:00:22 +0530
branchbuildout
changeset 237 2c72b08003f5
parent 227 3c8f3b0e5b00
permissions -rw-r--r--
This branch is dead. So it should fall out.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
227
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
##############################################################################
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
#
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
# Copyright (c) 2006 Zope Foundation and Contributors.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
# All Rights Reserved.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
#
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
# This software is subject to the provisions of the Zope Public License,
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
# FOR A PARTICULAR PURPOSE.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
#
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
##############################################################################
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
"""Bootstrap a buildout-based project
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
Simply run this script in a directory containing a buildout.cfg.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
The script accepts buildout command-line options, so you can
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
use the -c option to specify an alternate configuration file.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
"""
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
import os, shutil, sys, tempfile, textwrap, urllib, urllib2, subprocess
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
from optparse import OptionParser
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
if sys.platform == 'win32':
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
    def quote(c):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
        if ' ' in c:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
            return '"%s"' % c # work around spawn lamosity on windows
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
        else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
            return c
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
    quote = str
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
# See zc.buildout.easy_install._has_broken_dash_S for motivation and comments.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
stdout, stderr = subprocess.Popen(
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
    [sys.executable, '-Sc',
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
     'try:\n'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
     '    import ConfigParser\n'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
     'except ImportError:\n'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
     '    print 1\n'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
     'else:\n'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
     '    print 0\n'],
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
    stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
has_broken_dash_S = bool(int(stdout.strip()))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
# In order to be more robust in the face of system Pythons, we want to
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
# run without site-packages loaded.  This is somewhat tricky, in
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
# particular because Python 2.6's distutils imports site, so starting
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
# with the -S flag is not sufficient.  However, we'll start with that:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
if not has_broken_dash_S and 'site' in sys.modules:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
    # We will restart with python -S.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
    args = sys.argv[:]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
    args[0:0] = [sys.executable, '-S']
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
    args = map(quote, args)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
    os.execv(sys.executable, args)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
# Now we are running with -S.  We'll get the clean sys.path, import site
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
# because distutils will do it later, and then reset the path and clean
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
# out any namespace packages from site-packages that might have been
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
# loaded by .pth files.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
clean_path = sys.path[:]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
import site
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
sys.path[:] = clean_path
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
for k, v in sys.modules.items():
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
    if k in ('setuptools', 'pkg_resources') or (
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
        hasattr(v, '__path__') and
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
        len(v.__path__)==1 and
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
        not os.path.exists(os.path.join(v.__path__[0],'__init__.py'))):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
        # This is a namespace package.  Remove it.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
        sys.modules.pop(k)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
is_jython = sys.platform.startswith('java')
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
setuptools_source = 'http://peak.telecommunity.com/dist/ez_setup.py'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
distribute_source = 'http://python-distribute.org/distribute_setup.py'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
# parsing arguments
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
def normalize_to_url(option, opt_str, value, parser):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
    if value:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
        if '://' not in value: # It doesn't smell like a URL.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
            value = 'file://%s' % (
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
                urllib.pathname2url(
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
                    os.path.abspath(os.path.expanduser(value))),)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
        if opt_str == '--download-base' and not value.endswith('/'):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
            # Download base needs a trailing slash to make the world happy.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
            value += '/'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
    else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
        value = None
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
    name = opt_str[2:].replace('-', '_')
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
    setattr(parser.values, name, value)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
usage = '''\
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
Bootstraps a buildout-based project.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
Simply run this script in a directory containing a buildout.cfg, using the
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
Python that you want bin/buildout to use.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
Note that by using --setup-source and --download-base to point to
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
local resources, you can keep this script from going over the network.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
'''
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
parser = OptionParser(usage=usage)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
parser.add_option("-v", "--version", dest="version",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
                          help="use a specific zc.buildout version")
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
parser.add_option("-d", "--distribute",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
                   action="store_true", dest="use_distribute", default=False,
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
                   help="Use Distribute rather than Setuptools.")
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
parser.add_option("--setup-source", action="callback", dest="setup_source",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
                  callback=normalize_to_url, nargs=1, type="string",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
                  help=("Specify a URL or file location for the setup file. "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
                        "If you use Setuptools, this will default to " +
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
                        setuptools_source + "; if you use Distribute, this "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
                        "will default to " + distribute_source +"."))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
parser.add_option("--download-base", action="callback", dest="download_base",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
                  callback=normalize_to_url, nargs=1, type="string",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
                  help=("Specify a URL or directory for downloading "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
                        "zc.buildout and either Setuptools or Distribute. "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
                        "Defaults to PyPI."))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
parser.add_option("--eggs",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
                  help=("Specify a directory for storing eggs.  Defaults to "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
                        "a temporary directory that is deleted when the "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
                        "bootstrap script completes."))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
parser.add_option("-t", "--accept-buildout-test-releases",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
                  dest='accept_buildout_test_releases',
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
                  action="store_true", default=False,
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
                  help=("Normally, if you do not specify a --version, the "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
                        "bootstrap script and buildout gets the newest "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
                        "*final* versions of zc.buildout and its recipes and "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   129
                        "extensions for you.  If you use this flag, "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
                        "bootstrap and buildout will get the newest releases "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
                        "even if they are alphas or betas."))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
parser.add_option("-c", None, action="store", dest="config_file",
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
                   help=("Specify the path to the buildout configuration "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
                         "file to be used."))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   135
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
options, args = parser.parse_args()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
# if -c was provided, we push it back into args for buildout's main function
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
if options.config_file is not None:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
    args += ['-c', options.config_file]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
if options.eggs:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
    eggs_dir = os.path.abspath(os.path.expanduser(options.eggs))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
    eggs_dir = tempfile.mkdtemp()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
if options.setup_source is None:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
    if options.use_distribute:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
        options.setup_source = distribute_source
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
    else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
        options.setup_source = setuptools_source
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
if options.accept_buildout_test_releases:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
    args.append('buildout:accept-buildout-test-releases=true')
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
args.append('bootstrap')
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
try:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
    import pkg_resources
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   159
    import setuptools # A flag.  Sometimes pkg_resources is installed alone.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   160
    if not hasattr(pkg_resources, '_distribute'):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
        raise ImportError
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   162
except ImportError:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
    ez_code = urllib2.urlopen(
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   164
        options.setup_source).read().replace('\r\n', '\n')
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
    ez = {}
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
    exec ez_code in ez
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
    setup_args = dict(to_dir=eggs_dir, download_delay=0)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
    if options.download_base:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
        setup_args['download_base'] = options.download_base
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
    if options.use_distribute:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
        setup_args['no_fake'] = True
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
    ez['use_setuptools'](**setup_args)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
    if 'pkg_resources' in sys.modules:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
        reload(sys.modules['pkg_resources'])
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
    import pkg_resources
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
    # This does not (always?) update the default working set.  We will
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
    # do it.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
    for path in sys.path:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
        if path not in pkg_resources.working_set.entries:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
            pkg_resources.working_set.add_entry(path)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
cmd = [quote(sys.executable),
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
       '-c',
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
       quote('from setuptools.command.easy_install import main; main()'),
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
       '-mqNxd',
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
       quote(eggs_dir)]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
if not has_broken_dash_S:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
    cmd.insert(1, '-S')
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
find_links = options.download_base
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
if not find_links:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
    find_links = os.environ.get('bootstrap-testing-find-links')
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
if find_links:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
    cmd.extend(['-f', quote(find_links)])
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
if options.use_distribute:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
    setup_requirement = 'distribute'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
else:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
    setup_requirement = 'setuptools'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
ws = pkg_resources.working_set
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
setup_requirement_path = ws.find(
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
    pkg_resources.Requirement.parse(setup_requirement)).location
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
env = dict(
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
    os.environ,
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
    PYTHONPATH=setup_requirement_path)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
requirement = 'zc.buildout'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
version = options.version
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
if version is None and not options.accept_buildout_test_releases:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
    # Figure out the most recent final version of zc.buildout.
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
    import setuptools.package_index
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
    _final_parts = '*final-', '*final'
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
    def _final_version(parsed_version):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
        for part in parsed_version:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
            if (part[:1] == '*') and (part not in _final_parts):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
                return False
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
        return True
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   219
    index = setuptools.package_index.PackageIndex(
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
        search_path=[setup_requirement_path])
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
    if find_links:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
        index.add_find_links((find_links,))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
    req = pkg_resources.Requirement.parse(requirement)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
    if index.obtain(req) is not None:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
        best = []
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
        bestv = None
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
        for dist in index[req.project_name]:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
            distv = dist.parsed_version
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   229
            if _final_version(distv):
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   230
                if bestv is None or distv > bestv:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
                    best = [dist]
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232
                    bestv = distv
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   233
                elif distv == bestv:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   234
                    best.append(dist)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   235
        if best:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   236
            best.sort()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   237
            version = best[-1].version
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
if version:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   239
    requirement = '=='.join((requirement, version))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   240
cmd.append(requirement)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   241
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   242
if is_jython:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   243
    import subprocess
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   244
    exitcode = subprocess.Popen(cmd, env=env).wait()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
else: # Windows prefers this, apparently; otherwise we would prefer subprocess
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   246
    exitcode = os.spawnle(*([os.P_WAIT, sys.executable] + cmd + [env]))
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   247
if exitcode != 0:
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   248
    sys.stdout.flush()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   249
    sys.stderr.flush()
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   250
    print ("An error occurred when trying to install zc.buildout. "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   251
           "Look above this message for any errors that "
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
           "were output by easy_install.")
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   253
    sys.exit(exitcode)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
ws.add_entry(eggs_dir)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
ws.require(requirement)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
import zc.buildout.buildout
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   258
zc.buildout.buildout.main(args)
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   259
if not options.eggs: # clean up temporary egg directory
3c8f3b0e5b00 Add support for buildout and move the files to the directory to support buildout structure.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   260
    shutil.rmtree(eggs_dir)