changeset 6:6f8f390ab0b4

add option to run a command
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 20 Apr 2010 15:20:06 -0700
parents 3f9fac577d75
children d2daa42c1a56
files stampit/main.py
diffstat 1 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/stampit/main.py	Tue Apr 20 14:51:47 2010 -0700
+++ b/stampit/main.py	Tue Apr 20 15:20:06 2010 -0700
@@ -39,20 +39,23 @@
     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('-c', '--command',
+                      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")
     parser.add_option('-d', '--directory',
                       help='directory to use as the virtualenv')
+    parser.add_option('-o', '--output',
+                      help='where to put the tarballs')
+    parser.add_option('--verbose', default=False, action='store_true',
+                      help='more output')
     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)
+    callargs = options.verbose and {} or { 'stdout': subprocess.PIPE }
     if not args:
         parser.print_help()
         sys.exit(0)
-    if not options.name:
-        options.name = '+'.join(args)
 
     # locate virtualenv
     if options.virtualenv:
@@ -67,24 +70,40 @@
     # create a virtualenv
     if not options.directory:
         options.directory = tempfile.mkdtemp(dir=os.getcwd())
-    call([options.virtualenv, '--no-site-packages', options.directory])
+    call([options.virtualenv, '--no-site-packages', options.directory], **callargs)
 
     # install the packages
     pip = os.path.join(options.directory, 'bin', 'pip')
     command = [ pip, 'install', '--no-install' ]
     command.extend(args)
-    call(command)
+    call(command, **callargs)
 
     # make the tarballs
-    distdir = os.path.join(options.directory, 'dist')
+    if not options.output:
+        options.output = os.path.join(options.directory, 'dist')
     builddir = os.path.join(options.directory, 'build') # virtualenv creates
-    os.mkdir(distdir)
+    if not os.path.exists(options.output):
+        os.mkdir(options.output)
     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))
+        call([python, 'setup.py', 'sdist', '--dist-dir', options.output],
+             **callargs)
+    print 'Tarballs are in %s:' % options.output
+    tarballs = os.listdir(options.output) # XXX should be just new ones maybe
+    print '\n'.join(tarballs)
+
+    # do something with them (optionally)
+    if not options.command:
+        sys.exit(0) # you're done!
+    options.command = options.command.strip()
+    os.chdir(options.output)
+    for tarball in tarballs:
+        if '{}' in options.command:
+            command = options.command.replace('{}', tarball)
+        else:
+            command = '%s %s' % (options.command, tarball)
+        subprocess.call(command, shell=True)
 
 if __name__ == '__main__':
     main()