# HG changeset patch # User Jeff Hammel # Date 1271797935 25200 # Node ID 6ef0e769248d9fd72bcfcbce8115a5ff37589dca # Parent 164af2a4d2919b842292ecd27338890aed7430e8 add initial workflow diff -r 164af2a4d291 -r 6ef0e769248d stampit/main.py --- a/stampit/main.py Mon Apr 19 15:17:08 2010 -0700 +++ b/stampit/main.py Tue Apr 20 14:12:15 2010 -0700 @@ -9,29 +9,71 @@ mozmill-1.4.1-linux.tar.gz """ +import os +import subprocess import sys +import tempfile from optparse import OptionParser, IndentedHelpFormatter, HelpFormatter -from subprocess import call +from utils import which + +def call(*args, **kwargs): + code = subprocess.call(*args, **kwargs) + if code: + sys.exit(code) class UnformattedDescription(IndentedHelpFormatter): def format_description(self, description): return description.strip() or '' def main(args=sys.argv[1:]): + + del os.environ['PYTHONHOME'] # just make sure this is killed + + # parse options usage = '%prog [options] ' parser = OptionParser(usage, description=globals()['__doc__'], formatter=UnformattedDescription()) + parser.add_option('-b', '--name', + help='name of the bundle') + parser.add_option('-d', '--directory', + help='directory to use as the virtualenv') parser.add_option('--version', help='version of the package to be installed (defaults to the current on the cheeseshop)') + parser.add_option('--virtualenv', + help='path to virtualenv to use') options, args = parser.parse_args(args) - if not args: parser.print_help() sys.exit(0) + if not options.name: + options.name = '+'.join(args) + + # locate virtualenv + if not options.virtualenv: + options.virtualenv = which('virtualenv') + if not os.path.exist(options.virtualenv): + parser.error("'%s', specified by --virtualenv, does not exist") + if options.virtualenv is None: + # TODO: download virtualenv for them + parser.error("virtualenv cannot be found; please install virtualenv or specify its location with --virtualenv") # create a virtualenv -# call(['virtualenv']) + if not options.directory: + options.directory = tempfile.mkdtemp(dir=os.getcwd()) + call([options.virtualenv, '--no-site-packages', options.directory]) + oldpwd = os.getcwd() + os.chdir(options.directory) + + # install the packages + bundlename = options.name + '.pybundle' + command = [ 'bin/pip', 'bundle', bundlename ] + command.extend(args) + call(command) + command = ['bin/pip', 'install', bundlename ] + + # get the versions + if __name__ == '__main__': main() diff -r 164af2a4d291 -r 6ef0e769248d stampit/utils.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stampit/utils.py Tue Apr 20 14:12:15 2010 -0700 @@ -0,0 +1,13 @@ +""" +utility functions +""" + +import os + +def which(exectuable): + for directory in os.environ['PATH'].split(os.pathsep): + path = os.path.join(dir, executable) + if os.path.exists(path): + return path + +