/docs/flickr2couchdb Gawel's repository

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