changeset 3:6ef0e769248d

add initial workflow
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 20 Apr 2010 14:12:15 -0700
parents 164af2a4d291
children 95b9f262d795
files stampit/main.py stampit/utils.py
diffstat 2 files changed, 58 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/stampit/main.py	Mon Apr 19 15:17:08 2010 -0700
+++ b/stampit/main.py	Tue Apr 20 14:12:15 2010 -0700
@@ -9,29 +9,71 @@
 mozmill-1.4.1-linux.tar.gz
 """
 
+import os
+import subprocess
 import sys
+import tempfile
 
 from optparse import OptionParser, IndentedHelpFormatter, HelpFormatter
-from subprocess import call
+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:]):
+    
+    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 not options.virtualenv:
+        options.virtualenv = which('virtualenv')
+    if not os.path.exist(options.virtualenv):
+        parser.error("'%s', specified by --virtualenv, does not exist")
+    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
-#    call(['virtualenv'])
+    if not options.directory:
+        options.directory = tempfile.mkdtemp(dir=os.getcwd())
+    call([options.virtualenv, '--no-site-packages', options.directory])
+    oldpwd = os.getcwd()
+    os.chdir(options.directory)
+
+    # install the packages
+    bundlename = options.name + '.pybundle'
+    command = [ 'bin/pip', 'bundle', bundlename ]
+    command.extend(args)
+    call(command)
+    command = ['bin/pip', 'install', bundlename ]
+
+    # get the versions
+    
 
 if __name__ == '__main__':
     main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stampit/utils.py	Tue Apr 20 14:12:15 2010 -0700
@@ -0,0 +1,13 @@
+"""
+utility functions
+"""
+
+import os
+
+def which(exectuable):
+  for directory in os.environ['PATH'].split(os.pathsep):
+    path = os.path.join(dir, executable)
+    if os.path.exists(path):
+      return path
+
+