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