view buttercup/checkout.py @ 53:af4155b0a260 default tip

add --prefix option
author Jeff Hammel <k0scist@gmail.com>
date Tue, 03 Nov 2020 07:59:36 -0800
parents b717de8b384f
children
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

from optparse import OptionParser

from . import source
from .buttercup import Buttercup

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

    # parse command line options
    parser = OptionParser()
    parser.add_option('--setup', action="store_true", default=False,
                      help="install the packages")
    parser.add_option('--list', action="store_true", default=False,
                      help="list the source to be installed")
    parser.add_option('--prefix',
                      help="prefix or http://k0s.org/hg if not specified")
    options, args = parser.parse_args(args)

    # list sources if specified
    if options.list:
        buttercup = Buttercup(srcdir=None, prefix=options.prefix)
        sources = source.sources(buttercup.sources)
        for s in sources:
            print('%s: %s' % (s.directory_name(s.uri), s.uri))
        return

    # setup the src directory in a virtualenv
    if 'VIRTUAL_ENV' not in os.environ:
        raise AssertionError("You must have a virtualenv activated")
    src = os.path.join(os.environ['VIRTUAL_ENV'], 'src')
    if not os.path.exists(src):
        os.mkdir(src)

    # grow a flower
    buttercup = Buttercup(srcdir=src, prefix=options.prefix)

    # clone/update the sources
    buttercup.install()
    # install the python
    if options.setup:
        buttercup.setup()

if __name__ == '__main__':
    sys.exit(main() or 0)