view buttercup/checkout.py @ 16:5e5af2af69bf

correct message format
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 24 Nov 2010 22:51:30 -0800
parents 907bc7300be3
children 151862a0a711
line wrap: on
line source

#!/usr/bin/env python

"""
checks out the source as associated with the buttercup package
"""

# XXX could/should use e.g.
# pip install --editable hg+https://slinkp@bitbucket.org/slinkp/purplevoter#egg=purplevoter
# -or -
# pip install -r foo.txt

import os
import sys
import subprocess
from optparse import OptionParser

HG='http://k0s.org/hg'
PACKAGES=['bitsyapps',
          'bitsyauth',
          'bitsyblog',
          'bitsytweet',
          'buttercup',
          'clwapp',
          'commentator',
          'contenttransformer',
          'cropresize',
          'decoupage',
          'emaildispatcher',
          'genshi_view',
          'hgpaste',
          'lxmlmiddleware',
          'martINI',
          'montage',
          'webob_view',
          'wordstream']

def sources():
    return [(package, '%s/%s' % (HG, package))
            for package in PACKAGES ]

def main(args=sys.argv[1:]):

    # get source repositories
    sources = globals()['sources']()

    # parse command line options
    parser = OptionParser()
    parser.add_option('--install', action="store_true", default=False,
                      help="install the packages")
    parser.add_option('--update', action="store_true", default=False,
                      help="update the packages")
    parser.add_option('--list', action="store_true", default=False,
                      help="list the source to be installed")
    options, args = parser.parse_args(args)

    # list sources if specified
    if options.list:
        for source in sources:
            print source[0], source[1]
        sys.exit(0)

    # setup the src directory in a virtualenv
    assert 'VIRTUAL_ENV' in os.environ
    src = os.path.join(os.environ['VIRTUAL_ENV'], 'src')
    if not os.path.exists(src):
        os.mkdir(src)
    os.chdir(src)

    # clone othe sources
    for source in sources:
        if os.path.exists(source[0]):
            if options.update:
                os.chdir(source[0])
                subprocess.call(['hg', 'pull'])
                subprocess.call(['hg', 'update'])
                os.chdir('..')
            else:
                print "%s already exists" % source[0]
        else:
            subprocess.call(['hg', 'clone', source[1]])
            # TODO: add a more intelligent .hg/hgrc

    # install the sources
    if options.install:
        for source in sources:
            os.chdir(source[0])
            subprocess.call(['python', 'setup.py', 'develop'])
            os.chdir('..')

if __name__ == '__main__':
    main()