From: martin@piware.de <> Date: Thu, 1 Nov 2007 12:08:17 +0000 (-0400) Subject: add buildd.py X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=afe32515ad59a0da4f8e8d41151cd42e757684f3;p=bin.git add buildd.py --- diff --git a/buildd.py b/buildd.py new file mode 100755 index 0000000..f0467f2 --- /dev/null +++ b/buildd.py @@ -0,0 +1,70 @@ +#!/usr/bin/python + +# CLI for Launchpad buildd operations +# (C) 2007 Canonical Ltd. +# Author: Martin Pitt + +import urllib2, cookielib, re, sys, glob, os.path +from urllib import urlencode + +# parse arguments +try: + (package, release, op) = sys.argv[1:] +except ValueError: + print >> sys.stderr, '''Usage: %s + +operation: status | retry | rescore [priority (default 5000)]''' % sys.argv[0] + sys.exit(1) + +# find cookie file +try: + cookiefile = glob.glob(os.path.expanduser('~/.mozilla/firefox/*/cookies.txt'))[0] +except IndexError: + print >> sys.stderr, 'Could not find Firefox cookie file' + sys.exit(1) + +# build HTML opener with cookie file +cj = cookielib.MozillaCookieJar() +cj.load(cookiefile) +urlopener = urllib2.build_opener() +urlopener.add_handler(urllib2.HTTPCookieProcessor(cj)) + +# find out the version in given release +page = urlopener.open('https://launchpad.net/ubuntu/+source/' + package).read() +m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release, package), page) +if not m: + print >> sys.stderr, 'Cannot find this package' + sys.exit(1) +version = m.group(1) +print 'Source version:', version + +# parse out build URLs, states, and arches +buildstats = {} +page = urlopener.open('https://launchpad.net/ubuntu/+source/%s/%s' % (package, version)) +url = page.geturl() +page = page.read() +for m in re.finditer('"/ubuntu/\+source/%s/%s(/\+build/\d+)"[^\n]+\n\s*(\w+).*?(\w+).*?\s*([^\n]+)\n' % + (package, version), page, re.S): + if m.group(2) == release: + print '%s: %s' % (m.group(3), m.group(4)) + buildstats[url + m.group(1)] = [m.group(3).strip(), m.group(4).strip()] + +# operations +if op == 'status': + sys.exit(0) + +for build, (arch, status) in buildstats.iteritems(): + if op == 'rescore': + if status == 'Needs building': + print 'rescoring', build, '(%s)' % arch + urlopener.open(build+'/+rescore', urlencode( + {'SCORE': '5000', 'RESCORE': '1'})) + elif op == 'retry': + if status == 'Failed to build': + print 'retrying', build, '(%s)' % arch + urlopener.open(build+'/+retry', urlencode( + {'RETRY': '1'})) + + else: + print >> sys.stderr, 'Invalid operation' + sys.exit(1)