3 # CLI for Launchpad buildd operations
4 # (C) 2007 Canonical Ltd.
5 # Author: Martin Pitt <martin.pitt@canonical.com>
7 import urllib2, cookielib, re, sys, glob, os.path
8 from urllib import urlencode
12 (package, release, op) = sys.argv[1:]
14 print >> sys.stderr, '''Usage: %s <srcpackage> <release> <operation>
16 operation: status | retry | rescore [priority (default 5000)]''' % sys.argv[0]
21 cookiefile = glob.glob(os.path.expanduser('~/.mozilla/firefox/*/cookies.txt'))[0]
23 print >> sys.stderr, 'Could not find Firefox cookie file'
26 # build HTML opener with cookie file
27 cj = cookielib.MozillaCookieJar()
29 urlopener = urllib2.build_opener()
30 urlopener.add_handler(urllib2.HTTPCookieProcessor(cj))
32 # find out the version in given release
33 page = urlopener.open('https://launchpad.net/ubuntu/+source/' + package).read()
34 m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release, package), page)
36 print >> sys.stderr, 'Cannot find this package'
39 print 'Source version:', version
41 # parse out build URLs, states, and arches
43 page = urlopener.open('https://launchpad.net/ubuntu/+source/%s/%s' % (package, version))
46 for m in re.finditer('"/ubuntu/\+source/%s/%s(/\+build/\d+)"[^\n]+\n\s*(\w+).*?<span>(\w+)</span>.*?</a>\s*([^\n]+)\n' %
47 (package, version), page, re.S):
48 if m.group(2) == release:
49 print '%s: %s' % (m.group(3), m.group(4))
50 buildstats[url + m.group(1)] = [m.group(3).strip(), m.group(4).strip()]
56 for build, (arch, status) in buildstats.iteritems():
58 if status == 'Needs building':
59 print 'rescoring', build, '(%s)' % arch
60 urlopener.open(build+'/+rescore', urlencode(
61 {'SCORE': '5000', 'RESCORE': '1'}))
63 if status == 'Failed to build':
64 print 'retrying', build, '(%s)' % arch
65 urlopener.open(build+'/+retry', urlencode(
69 print >> sys.stderr, 'Invalid operation'