Mercurial > hg > stampit
view stampit/main.py @ 5:3f9fac577d75
this now actually makes some tarballs for you
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 20 Apr 2010 14:51:47 -0700 |
parents | 95b9f262d795 |
children | 6f8f390ab0b4 |
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:]): # XXX this is actually a very long way to work around just getting the # tarballs as pip magically does this for you! ::sigh:: # not sure of a better/easier way, though if 'PYTHONHOME' in os.environ: 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 options.virtualenv: if not os.path.exists(options.virtualenv): parser.error("'%s', specified by --virtualenv, does not exist") else: options.virtualenv = which('virtualenv') 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]) # install the packages pip = os.path.join(options.directory, 'bin', 'pip') command = [ pip, 'install', '--no-install' ] command.extend(args) call(command) # make the tarballs distdir = os.path.join(options.directory, 'dist') builddir = os.path.join(options.directory, 'build') # virtualenv creates os.mkdir(distdir) python = os.path.join(options.directory, 'bin', 'python') for package in os.listdir(builddir): os.chdir(os.path.join(builddir, package)) call([python, 'setup.py', 'sdist', '--dist-dir', distdir]) print 'Tarballs are in %s:' % distdir print '\n'.join(os.listdir(distdir)) if __name__ == '__main__': main()