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]
20 cookiefile = os.path.expanduser('~/.lpcookie')
21 if not os.path.exists(cookiefile):
23 cookiefile = glob.glob(os.path.expanduser('~/.mozilla/*/*/cookies.txt'))[0]
25 print >> sys.stderr, 'Could not find Firefox cookie file'
28 # build HTML opener with cookie file
29 cj = cookielib.MozillaCookieJar()
31 urlopener = urllib2.build_opener()
32 urlopener.add_handler(urllib2.HTTPCookieProcessor(cj))
34 # find out the version in given release
36 page = urlopener.open('https://launchpad.net/ubuntu/+source/' + package).read()
37 except urllib2.HTTPError:
38 print >> sys.stderr, 'This source does not appear to exist in Ubuntu'
41 m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release, package.replace('+', '\+')), page)
43 print >> sys.stderr, 'Cannot find this source package in this release'
46 print 'Source version:', version
48 # parse out build URLs, states, and arches
50 page = urlopener.open('https://launchpad.net/ubuntu/+source/%s/%s' % (package, version))
53 for m in re.finditer('"/ubuntu/\+source/%s/%s(/\+build/\d+)"[^\n]+\n\s*(\w+).*?<span>(\w+)</span>.*?</a>\s*([^\n]+)\n' %
54 (package.replace('+', '\+'), version.replace('+', '\+')), page, re.S):
55 if m.group(2) == release:
56 print '%s: %s' % (m.group(3), m.group(4))
57 buildstats[url + m.group(1)] = [m.group(3).strip(), m.group(4).strip()]
63 for build, (arch, status) in buildstats.iteritems():
65 if status == 'Needs building':
66 print 'rescoring', build, '(%s)' % arch
67 urlopener.open(build+'/+rescore', urlencode(
68 {'SCORE': '5000', 'RESCORE': '1'}))
70 if status in ('Failed to build', 'Chroot problem', 'Failed to upload'):
71 print 'retrying', build, '(%s)' % arch
72 urlopener.open(build+'/+retry', urlencode(
76 print >> sys.stderr, 'Invalid operation'