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/*/*/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
34 page = urlopener.open('https://launchpad.net/ubuntu/+source/' + package).read()
35 except urllib2.HTTPError:
36 print >> sys.stderr, 'This source does not appear to exist in Ubuntu'
39 m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release, package.replace('+', '\+')), page)
41 print >> sys.stderr, 'Cannot find this source package in this release'
44 print 'Source version:', version
46 # parse out build URLs, states, and arches
48 page = urlopener.open('https://launchpad.net/ubuntu/+source/%s/%s' % (package, version))
51 for m in re.finditer('"/ubuntu/\+source/%s/%s(/\+build/\d+)"[^\n]+\n\s*(\w+).*?<span>(\w+)</span>.*?</a>\s*([^\n]+)\n' %
52 (package.replace('+', '\+'), version.replace('+', '\+')), page, re.S):
53 if m.group(2) == release:
54 print '%s: %s' % (m.group(3), m.group(4))
55 buildstats[url + m.group(1)] = [m.group(3).strip(), m.group(4).strip()]
61 for build, (arch, status) in buildstats.iteritems():
63 if status == 'Needs building':
64 print 'rescoring', build, '(%s)' % arch
65 urlopener.open(build+'/+rescore', urlencode(
66 {'SCORE': '5000', 'RESCORE': '1'}))
68 if status in ('Failed to build', 'Chroot problem', 'Failed to upload'):
69 print 'retrying', build, '(%s)' % arch
70 urlopener.open(build+'/+retry', urlencode(
74 print >> sys.stderr, 'Invalid operation'