diff tests/upload_mozbase.py @ 71:dcb98ad8463e

add a convenience script to post the mozbase packages; should be converted to a test
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 02 Mar 2012 11:29:57 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/upload_mozbase.py	Fri Mar 02 11:29:57 2012 -0800
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+
+"""
+upload mozbase from tip:
+https://github.com/mozilla/mozbase
+"""
+
+LOCATION = 'https://github.com/mozilla/mozbase/tarball/master'
+
+import multipart
+import optparse
+import os
+import shutil
+import subprocess
+import sys
+import tarfile
+import tempfile
+import urllib2
+from StringIO import StringIO
+try:
+    from subprocess import check_call as call
+except ImportError:
+    from subprocess import call
+
+# parse command line options
+usage = '%prog http://url.of/package/index'
+parser = optparse.OptionParser(usage=usage, description=__doc__)
+options, args = parser.parse_args()
+if not len(args) == 1:
+    parser.print_usage()
+    parser.exit(1)
+url = args[0]
+
+# grab the tarball
+fd, buffer = tempfile.mkstemp()
+os.write(fd, urllib2.urlopen(LOCATION).read())
+os.close(fd)
+tf = tarfile.open(buffer)
+
+# extract to a temporary location
+tmpdir = tempfile.mkdtemp()
+tf.extractall(tmpdir)
+os.remove(buffer)
+dirlisting = os.listdir(tmpdir)
+assert len(dirlisting) == 1
+mozbase = os.path.join(tmpdir, dirlisting[0])
+
+# find the packages
+package_dirs = []
+for i in os.listdir(mozbase):
+    path = os.path.join(mozbase, i)
+    if os.path.isdir(path) and os.path.exists(os.path.join(path, 'setup.py')):
+        package_dirs.append(path)
+
+# create the sdists
+sdists = []
+for directory in package_dirs:
+    call([sys.executable, 'setup.py', 'sdist'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=directory)
+    dist = os.path.join(directory, 'dist')
+    assert os.path.exists(path) and os.path.isdir(path)
+    dirlisting = os.listdir(dist)
+    tarballs = [i for i in dirlisting if i.endswith('.tar.gz')]
+    # the dirlisting should actually only have one file anyway
+    # but just to be sure
+    assert len(tarballs) == 1
+    sdists.append(os.path.join(dist, tarballs[0]))
+
+# upload the sdists
+for sdist in sdists:
+    upload = multipart.MultiPartForm()
+    upload.add_file('package', sdist)
+    upload.post(url)
+
+# remove the temporary directory
+shutil.rmtree(tmpdir)