Mercurial > hg > stampit
annotate 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 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 """ | |
3 tar up a set of packages in a virtualenv per platform: | |
4 | |
5 <package>-<version>-<platform>.tar.gz | |
6 | |
7 Example: | |
8 | |
9 mozmill-1.4.1-linux.tar.gz | |
10 """ | |
11 | |
3 | 12 import os |
13 import subprocess | |
0 | 14 import sys |
3 | 15 import tempfile |
0 | 16 |
2
164af2a4d291
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
17 from optparse import OptionParser, IndentedHelpFormatter, HelpFormatter |
3 | 18 from utils import which |
19 | |
20 def call(*args, **kwargs): | |
21 code = subprocess.call(*args, **kwargs) | |
22 if code: | |
23 sys.exit(code) | |
0 | 24 |
2
164af2a4d291
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
25 class UnformattedDescription(IndentedHelpFormatter): |
164af2a4d291
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
26 def format_description(self, description): |
164af2a4d291
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
27 return description.strip() or '' |
0 | 28 |
29 def main(args=sys.argv[1:]): | |
4
95b9f262d795
check for PYTHONHOME before deleting it
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
30 |
5
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
31 # XXX this is actually a very long way to work around just getting the |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
32 # tarballs as pip magically does this for you! ::sigh:: |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
33 # not sure of a better/easier way, though |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
34 |
4
95b9f262d795
check for PYTHONHOME before deleting it
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
35 if 'PYTHONHOME' in os.environ: |
95b9f262d795
check for PYTHONHOME before deleting it
Jeff Hammel <jhammel@mozilla.com>
parents:
3
diff
changeset
|
36 del os.environ['PYTHONHOME'] # just make sure this is killed |
3 | 37 |
38 # parse options | |
0 | 39 usage = '%prog [options] <package> <platform>' |
2
164af2a4d291
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
40 parser = OptionParser(usage, description=globals()['__doc__'], |
164af2a4d291
better description formatting
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
41 formatter=UnformattedDescription()) |
3 | 42 parser.add_option('-b', '--name', |
43 help='name of the bundle') | |
44 parser.add_option('-d', '--directory', | |
45 help='directory to use as the virtualenv') | |
0 | 46 parser.add_option('--version', |
47 help='version of the package to be installed (defaults to the current on the cheeseshop)') | |
3 | 48 parser.add_option('--virtualenv', |
49 help='path to virtualenv to use') | |
0 | 50 options, args = parser.parse_args(args) |
1
820beace15f2
get description from module docstring
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
51 if not args: |
820beace15f2
get description from module docstring
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
52 parser.print_help() |
820beace15f2
get description from module docstring
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
53 sys.exit(0) |
3 | 54 if not options.name: |
55 options.name = '+'.join(args) | |
56 | |
57 # locate virtualenv | |
5
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
58 if options.virtualenv: |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
59 if not os.path.exists(options.virtualenv): |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
60 parser.error("'%s', specified by --virtualenv, does not exist") |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
61 else: |
3 | 62 options.virtualenv = which('virtualenv') |
63 if options.virtualenv is None: | |
64 # TODO: download virtualenv for them | |
65 parser.error("virtualenv cannot be found; please install virtualenv or specify its location with --virtualenv") | |
1
820beace15f2
get description from module docstring
Jeff Hammel <jhammel@mozilla.com>
parents:
0
diff
changeset
|
66 |
0 | 67 # create a virtualenv |
3 | 68 if not options.directory: |
69 options.directory = tempfile.mkdtemp(dir=os.getcwd()) | |
70 call([options.virtualenv, '--no-site-packages', options.directory]) | |
71 | |
72 # install the packages | |
5
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
73 pip = os.path.join(options.directory, 'bin', 'pip') |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
74 command = [ pip, 'install', '--no-install' ] |
3 | 75 command.extend(args) |
76 call(command) | |
77 | |
5
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
78 # make the tarballs |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
79 distdir = os.path.join(options.directory, 'dist') |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
80 builddir = os.path.join(options.directory, 'build') # virtualenv creates |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
81 os.mkdir(distdir) |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
82 python = os.path.join(options.directory, 'bin', 'python') |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
83 for package in os.listdir(builddir): |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
84 os.chdir(os.path.join(builddir, package)) |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
85 call([python, 'setup.py', 'sdist', '--dist-dir', distdir]) |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
86 print 'Tarballs are in %s:' % distdir |
3f9fac577d75
this now actually makes some tarballs for you
Jeff Hammel <jhammel@mozilla.com>
parents:
4
diff
changeset
|
87 print '\n'.join(os.listdir(distdir)) |
0 | 88 |
89 if __name__ == '__main__': | |
90 main() |