Mercurial > hg > stampit
comparison stampit/main.py @ 7:d2daa42c1a56
add some more options
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 20 Apr 2010 15:56:29 -0700 |
parents | 6f8f390ab0b4 |
children | 8c3361ab1db2 |
comparison
equal
deleted
inserted
replaced
6:6f8f390ab0b4 | 7:d2daa42c1a56 |
---|---|
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 | 12 import os |
13 import shutil | |
13 import subprocess | 14 import subprocess |
14 import sys | 15 import sys |
15 import tempfile | 16 import tempfile |
16 | 17 |
17 from optparse import OptionParser, IndentedHelpFormatter, HelpFormatter | 18 from optparse import OptionParser, IndentedHelpFormatter, HelpFormatter |
43 help="command to use on each tarball; the tarball will be the last argument to the command, or '{}' may be used, find-style, to substittue for the argument") | 44 help="command to use on each tarball; the tarball will be the last argument to the command, or '{}' may be used, find-style, to substittue for the argument") |
44 parser.add_option('-d', '--directory', | 45 parser.add_option('-d', '--directory', |
45 help='directory to use as the virtualenv') | 46 help='directory to use as the virtualenv') |
46 parser.add_option('-o', '--output', | 47 parser.add_option('-o', '--output', |
47 help='where to put the tarballs') | 48 help='where to put the tarballs') |
49 parser.add_option('--clean', default=False, action='store_true', | |
50 help='remove all directories [BE CAREFUL!]') | |
51 parser.add_option('-q', '--quiet', default=False, action='store_true', | |
52 help='make less noise') | |
48 parser.add_option('--verbose', default=False, action='store_true', | 53 parser.add_option('--verbose', default=False, action='store_true', |
49 help='more output') | 54 help='more output') |
50 parser.add_option('--version', | 55 parser.add_option('--version', |
51 help='version of the package to be installed (defaults to the current on the cheeseshop)') | 56 help='version of the package to be installed (defaults to the current on the cheeseshop)') |
52 parser.add_option('--virtualenv', | 57 parser.add_option('--virtualenv', |
53 help='path to virtualenv to use') | 58 help='path to virtualenv to use') |
54 options, args = parser.parse_args(args) | 59 options, args = parser.parse_args(args) |
55 callargs = options.verbose and {} or { 'stdout': subprocess.PIPE } | 60 callargs = options.verbose and {} or { 'stdout': subprocess.PIPE } |
61 if options.quiet: | |
62 callargs['stderr'] = subprocess.PIPE | |
56 if not args: | 63 if not args: |
57 parser.print_help() | 64 parser.print_help() |
58 sys.exit(0) | 65 sys.exit(0) |
59 | 66 |
60 # locate virtualenv | 67 # locate virtualenv |
61 if options.virtualenv: | 68 if options.virtualenv: |
62 if not os.path.exists(options.virtualenv): | 69 if not os.path.exists(options.virtualenv): |
63 parser.error("'%s', specified by --virtualenv, does not exist") | 70 parser.error("'%s', specified by --virtualenv, does not exist") |
64 else: | 71 else: |
65 options.virtualenv = which('virtualenv') | 72 options.virtualenv = which('virtualenv') |
73 virtualenv_dir = None | |
66 if options.virtualenv is None: | 74 if options.virtualenv is None: |
67 # TODO: download virtualenv for them | 75 hg = which('hg') |
68 parser.error("virtualenv cannot be found; please install virtualenv or specify its location with --virtualenv") | 76 if hg: |
77 # download virtualenv for them | |
78 virtualenv_src = 'http://bitbucket.org/ianb/virtualenv' | |
79 virtualenv_dir = tempfile.mkdtemp() | |
80 call([hg, 'clone', virtualenv_src, virtualenv_dir], **callargs) | |
81 options.virtualenv = os.path.join(virtualenv_dir, 'virtualenv.py') | |
82 else: | |
83 parser.error("virtualenv cannot be found; please install virtualenv or specify its location with --virtualenv") | |
69 | 84 |
70 # create a virtualenv | 85 # create a virtualenv |
86 directory_exists = bool(options.directory and os.path.exists(options.directory)) | |
71 if not options.directory: | 87 if not options.directory: |
72 options.directory = tempfile.mkdtemp(dir=os.getcwd()) | 88 options.directory = tempfile.mkdtemp(dir=os.getcwd()) |
73 call([options.virtualenv, '--no-site-packages', options.directory], **callargs) | 89 call([options.virtualenv, '--no-site-packages', options.directory], **callargs) |
74 | 90 |
75 # install the packages | 91 # install the packages |
87 python = os.path.join(options.directory, 'bin', 'python') | 103 python = os.path.join(options.directory, 'bin', 'python') |
88 for package in os.listdir(builddir): | 104 for package in os.listdir(builddir): |
89 os.chdir(os.path.join(builddir, package)) | 105 os.chdir(os.path.join(builddir, package)) |
90 call([python, 'setup.py', 'sdist', '--dist-dir', options.output], | 106 call([python, 'setup.py', 'sdist', '--dist-dir', options.output], |
91 **callargs) | 107 **callargs) |
92 print 'Tarballs are in %s:' % options.output | |
93 tarballs = os.listdir(options.output) # XXX should be just new ones maybe | 108 tarballs = os.listdir(options.output) # XXX should be just new ones maybe |
94 print '\n'.join(tarballs) | 109 quiet = options.quiet or options.command |
110 if options.quiet: | |
111 if not options.command: | |
112 print '\n'.join([os.path.join(options.output, tarball) | |
113 for tarball in tarballs]) | |
114 else: | |
115 print 'Tarballs are in %s:' % options.output | |
116 print '\n'.join(tarballs) | |
95 | 117 |
96 # do something with them (optionally) | 118 # do something with them (optionally) |
97 if not options.command: | 119 if options.command: |
98 sys.exit(0) # you're done! | 120 sys.exit(0) # you're done! |
99 options.command = options.command.strip() | 121 options.command = options.command.strip() |
100 os.chdir(options.output) | 122 os.chdir(options.output) |
101 for tarball in tarballs: | 123 for tarball in tarballs: |
102 if '{}' in options.command: | 124 if '{}' in options.command: |
103 command = options.command.replace('{}', tarball) | 125 command = options.command.replace('{}', tarball) |
104 else: | 126 else: |
105 command = '%s %s' % (options.command, tarball) | 127 command = '%s %s' % (options.command, tarball) |
106 subprocess.call(command, shell=True) | 128 subprocess.call(command, shell=True) |
129 | |
130 # clean up (optionally) | |
131 if options.clean: | |
132 if virtualenv_dir: | |
133 shutil.rmtree(virtualenv_dir) | |
134 if not directory_exists: | |
135 shutil.rmtree(options.directory) | |
107 | 136 |
108 if __name__ == '__main__': | 137 if __name__ == '__main__': |
109 main() | 138 main() |