comparison 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
comparison
equal deleted inserted replaced
2:164af2a4d291 3:6ef0e769248d
7 Example: 7 Example:
8 8
9 mozmill-1.4.1-linux.tar.gz 9 mozmill-1.4.1-linux.tar.gz
10 """ 10 """
11 11
12 import os
13 import subprocess
12 import sys 14 import sys
15 import tempfile
13 16
14 from optparse import OptionParser, IndentedHelpFormatter, HelpFormatter 17 from optparse import OptionParser, IndentedHelpFormatter, HelpFormatter
15 from subprocess import call 18 from utils import which
19
20 def call(*args, **kwargs):
21 code = subprocess.call(*args, **kwargs)
22 if code:
23 sys.exit(code)
16 24
17 class UnformattedDescription(IndentedHelpFormatter): 25 class UnformattedDescription(IndentedHelpFormatter):
18 def format_description(self, description): 26 def format_description(self, description):
19 return description.strip() or '' 27 return description.strip() or ''
20 28
21 def main(args=sys.argv[1:]): 29 def main(args=sys.argv[1:]):
30
31 del os.environ['PYTHONHOME'] # just make sure this is killed
32
33 # parse options
22 usage = '%prog [options] <package> <platform>' 34 usage = '%prog [options] <package> <platform>'
23 parser = OptionParser(usage, description=globals()['__doc__'], 35 parser = OptionParser(usage, description=globals()['__doc__'],
24 formatter=UnformattedDescription()) 36 formatter=UnformattedDescription())
37 parser.add_option('-b', '--name',
38 help='name of the bundle')
39 parser.add_option('-d', '--directory',
40 help='directory to use as the virtualenv')
25 parser.add_option('--version', 41 parser.add_option('--version',
26 help='version of the package to be installed (defaults to the current on the cheeseshop)') 42 help='version of the package to be installed (defaults to the current on the cheeseshop)')
43 parser.add_option('--virtualenv',
44 help='path to virtualenv to use')
27 options, args = parser.parse_args(args) 45 options, args = parser.parse_args(args)
28
29 if not args: 46 if not args:
30 parser.print_help() 47 parser.print_help()
31 sys.exit(0) 48 sys.exit(0)
49 if not options.name:
50 options.name = '+'.join(args)
51
52 # locate virtualenv
53 if not options.virtualenv:
54 options.virtualenv = which('virtualenv')
55 if not os.path.exist(options.virtualenv):
56 parser.error("'%s', specified by --virtualenv, does not exist")
57 if options.virtualenv is None:
58 # TODO: download virtualenv for them
59 parser.error("virtualenv cannot be found; please install virtualenv or specify its location with --virtualenv")
32 60
33 # create a virtualenv 61 # create a virtualenv
34 # call(['virtualenv']) 62 if not options.directory:
63 options.directory = tempfile.mkdtemp(dir=os.getcwd())
64 call([options.virtualenv, '--no-site-packages', options.directory])
65 oldpwd = os.getcwd()
66 os.chdir(options.directory)
67
68 # install the packages
69 bundlename = options.name + '.pybundle'
70 command = [ 'bin/pip', 'bundle', bundlename ]
71 command.extend(args)
72 call(command)
73 command = ['bin/pip', 'install', bundlename ]
74
75 # get the versions
76
35 77
36 if __name__ == '__main__': 78 if __name__ == '__main__':
37 main() 79 main()