comparison 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
comparison
equal deleted inserted replaced
70:8fa30276b3e0 71:dcb98ad8463e
1 #!/usr/bin/env python
2
3 """
4 upload mozbase from tip:
5 https://github.com/mozilla/mozbase
6 """
7
8 LOCATION = 'https://github.com/mozilla/mozbase/tarball/master'
9
10 import multipart
11 import optparse
12 import os
13 import shutil
14 import subprocess
15 import sys
16 import tarfile
17 import tempfile
18 import urllib2
19 from StringIO import StringIO
20 try:
21 from subprocess import check_call as call
22 except ImportError:
23 from subprocess import call
24
25 # parse command line options
26 usage = '%prog http://url.of/package/index'
27 parser = optparse.OptionParser(usage=usage, description=__doc__)
28 options, args = parser.parse_args()
29 if not len(args) == 1:
30 parser.print_usage()
31 parser.exit(1)
32 url = args[0]
33
34 # grab the tarball
35 fd, buffer = tempfile.mkstemp()
36 os.write(fd, urllib2.urlopen(LOCATION).read())
37 os.close(fd)
38 tf = tarfile.open(buffer)
39
40 # extract to a temporary location
41 tmpdir = tempfile.mkdtemp()
42 tf.extractall(tmpdir)
43 os.remove(buffer)
44 dirlisting = os.listdir(tmpdir)
45 assert len(dirlisting) == 1
46 mozbase = os.path.join(tmpdir, dirlisting[0])
47
48 # find the packages
49 package_dirs = []
50 for i in os.listdir(mozbase):
51 path = os.path.join(mozbase, i)
52 if os.path.isdir(path) and os.path.exists(os.path.join(path, 'setup.py')):
53 package_dirs.append(path)
54
55 # create the sdists
56 sdists = []
57 for directory in package_dirs:
58 call([sys.executable, 'setup.py', 'sdist'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=directory)
59 dist = os.path.join(directory, 'dist')
60 assert os.path.exists(path) and os.path.isdir(path)
61 dirlisting = os.listdir(dist)
62 tarballs = [i for i in dirlisting if i.endswith('.tar.gz')]
63 # the dirlisting should actually only have one file anyway
64 # but just to be sure
65 assert len(tarballs) == 1
66 sdists.append(os.path.join(dist, tarballs[0]))
67
68 # upload the sdists
69 for sdist in sdists:
70 upload = multipart.MultiPartForm()
71 upload.add_file('package', sdist)
72 upload.post(url)
73
74 # remove the temporary directory
75 shutil.rmtree(tmpdir)