view tests/upload_mozbase.py @ 78:d5c3fdceb718

flush out tests section
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 02 Mar 2012 16:23:36 -0800
parents dcb98ad8463e
children
line wrap: on
line source

#!/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)