Mercurial > hg > stampit
view stampit/main.py @ 3:6ef0e769248d
add initial workflow
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 20 Apr 2010 14:12:15 -0700 |
parents | 164af2a4d291 |
children | 95b9f262d795 |
line wrap: on
line source
#!/usr/bin/env python """ tar up a set of packages in a virtualenv per platform: <package>-<version>-<platform>.tar.gz Example: mozmill-1.4.1-linux.tar.gz """ import os import subprocess import sys import tempfile from optparse import OptionParser, IndentedHelpFormatter, HelpFormatter 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] <package> <platform>' 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 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()