# HG changeset patch # User Jeff Hammel # Date 1330716597 28800 # Node ID dcb98ad8463e5a30e3aa9cc3456cd494e79794a2 # Parent 8fa30276b3e0f1539b1163fa19b97382cabea7ac add a convenience script to post the mozbase packages; should be converted to a test diff -r 8fa30276b3e0 -r dcb98ad8463e tests/upload_mozbase.py --- /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)