From 1db87055fda3ab5be164770ad2300151c6946583 Mon Sep 17 00:00:00 2001 From: utahta Date: Mon, 18 Jul 2011 22:31:13 +0900 Subject: [PATCH] Added buildout command --- .gitignore | 1 + pythonbrew/commands/buildout.py | 56 +++++++++++++++++++++++++++++++++ pythonbrew/define.py | 3 ++ pythonbrew/etc/config.cfg | 3 ++ 4 files changed, 63 insertions(+) create mode 100644 pythonbrew/commands/buildout.py diff --git a/.gitignore b/.gitignore index 1e2444e..1306759 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ pythonbrew.egg-info dist __pycache__ +*.swp diff --git a/pythonbrew/commands/buildout.py b/pythonbrew/commands/buildout.py new file mode 100644 index 0000000..bf81a40 --- /dev/null +++ b/pythonbrew/commands/buildout.py @@ -0,0 +1,56 @@ +import os +import sys +import subprocess +from pythonbrew.basecommand import Command +from pythonbrew.define import PATH_PYTHONS, BOOTSTRAP_DLSITE, PATH_DISTS +from pythonbrew.util import Package, get_current_python_path, Link +from pythonbrew.log import logger +from pythonbrew.downloader import Downloader + +class BuildoutCommand(Command): + name = "buildout" + usage = "%prog" + summary = "Runs the buildout against specified or currently use python" + + def __init__(self): + super(BuildoutCommand, self).__init__() + self.parser.add_option( + "-p", "--python", + dest="python", + default=None, + help="Use the specified version of python.", + metavar='VERSION' + ) + self.parser.disable_interspersed_args() + + def run_command(self, options, args): + if options.python: + python = Package(options.python).name + python = os.path.join(PATH_PYTHONS, python, 'bin', 'python') + if not os.path.isfile(python): + logger.info('%s is not installed.' % options.python) + sys.exit(1) + else: + python = get_current_python_path() + logger.info('Using %s' % python) + + # Download bootstrap.py + download_url = BOOTSTRAP_DLSITE + filename = Link(download_url).filename + bootstrap = os.path.join(PATH_DISTS, filename) + try: + d = Downloader() + d.download(filename, download_url, bootstrap) + except: + logger.error("Failed to download. `%s`" % download_url) + sys.exit(1) + + # Using bootstrap.py + if subprocess.call([python, bootstrap, '-d']): + logger.error('Failed to bootstrap.') + sys.exit(1) + + # Using buildout + subprocess.call(['./bin/buildout']) + +BuildoutCommand() diff --git a/pythonbrew/define.py b/pythonbrew/define.py index 593d2a7..761d829 100644 --- a/pythonbrew/define.py +++ b/pythonbrew/define.py @@ -53,6 +53,9 @@ def _get_or_default(section, option, default=''): # setuptools download DISTRIBUTE_SETUP_DLSITE = _get_or_default('distribute', 'url') +# buildout bootstrap download +BOOTSTRAP_DLSITE = _get_or_default('bootstrap', 'url') + # pythonbrew download PYTHONBREW_UPDATE_URL_MASTER = _get_or_default('pythonbrew', 'master') PYTHONBREW_UPDATE_URL_DEVELOP = _get_or_default('pythonbrew', 'develop') diff --git a/pythonbrew/etc/config.cfg b/pythonbrew/etc/config.cfg index dbdc698..1a16836 100644 --- a/pythonbrew/etc/config.cfg +++ b/pythonbrew/etc/config.cfg @@ -1,6 +1,9 @@ [distribute] url = http://python-distribute.org/distribute_setup.py +[bootstrap] +url = http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py + [pythonbrew] master = https://github.com/utahta/pythonbrew/tarball/master develop = https://github.com/utahta/pythonbrew/tarball/develop