From d3f18b8ec74ca7d3469caded7620f64938dd8ed0 Mon Sep 17 00:00:00 2001 From: Jonathan Patrick Davies Date: Mon, 11 Aug 2008 21:48:40 +0100 Subject: [PATCH] * buildd: Imported from Martin Pitt's scripts at: http://people.ubuntu.com/~pitti/scripts/buildd.py * ubuntutools/common.py: Python module to be used to enable the use of cookies to authenticate with Launchpad. * debian/ubuntu-dev-tools.install: Added line to install common.py above to the correct location. --- buildd | 84 ++++++++++++++++++++++++++++++ debian/changelog | 5 ++ debian/ubuntu-dev-tools.install | 1 + ubuntutools/common.py | 91 +++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+) create mode 100755 buildd create mode 100644 ubuntutools/common.py diff --git a/buildd b/buildd new file mode 100755 index 0000000..890bed6 --- /dev/null +++ b/buildd @@ -0,0 +1,84 @@ +#!/usr/bin/python +# +# buildd - command line interface for Launchpad buildd operations. +# +# Copyright (C) 2007 Canonical Ltd. +# Author: Martin Pitt . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import urllib2 +import re +import sys +from urllib import urlencode + +sys.path.append('/usr/share/ubuntu-dev-tools/') +import common + +# 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) + +# Prepare Launchpad cookie. +urlopener = common.prepareLaunchpadCookie() + +# Find out the version in given release. +try: + page = urlopener.open('https://launchpad.net/ubuntu/+source/' + package).read() +except urllib2.HTTPError: + print >> sys.stderr, 'This source does not appear to exist in Ubuntu' + sys.exit(1) + +m = re.search('"/ubuntu/%s/\+source/%s/(\d[^"]+)"' % (release, package.replace('+', '\+')), page) +if not m: + print >> sys.stderr, 'Cannot find this source package in this release' + 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.replace('+', '\+'), version.replace('+', '\+')), 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 in ('Failed to build', 'Chroot problem', 'Failed to upload'): + print 'retrying', build, '(%s)' % arch + urlopener.open(build+'/+retry', urlencode( + {'RETRY': '1'})) + else: + print >> sys.stderr, 'Invalid operation' + sys.exit(1) diff --git a/debian/changelog b/debian/changelog index b08c0a5..7f3fc01 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,11 @@ ubuntu-dev-tools (0.37ubuntu1) intrepid; urgency=low - Use optparse for option handling. - Check that the 'release' and 'package' actually exist on Launchpad. - Use subprocess for dget calls. + * buildd: Imported from Martin Pitt's scripts. + * ubuntutools/common.py: Python module to be used to enable the use of cookies + to authenticate with Launchpad. + * debian/ubuntu-dev-tools.install: Added line to install common.py above to + the correct location. [ Siegfried-Angel Gevatter Pujals ] * Add the GNU General Public License header to all scripts. diff --git a/debian/ubuntu-dev-tools.install b/debian/ubuntu-dev-tools.install index 40fadd6..72b8954 100644 --- a/debian/ubuntu-dev-tools.install +++ b/debian/ubuntu-dev-tools.install @@ -1 +1,2 @@ bash_completion/* etc/bash_completion.d/ +ubuntutools/common.py usr/share/ubuntu-dev-tools/ diff --git a/ubuntutools/common.py b/ubuntutools/common.py new file mode 100644 index 0000000..d3e2def --- /dev/null +++ b/ubuntutools/common.py @@ -0,0 +1,91 @@ +# +# common.py - provides functions which are commonly used by the +# ubuntu-dev-tools package. +# +# Copyright (C) 2008 Jonathan Patrick Davies +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# Based on code written by Martin Pitt and +# Kees Cook . + +""" Necessary modules. """ +import cookielib +import glob +import os.path +import sys +import urllib2 + +def prepareLaunchpadCookie(): + """ Search for a cookie file in the places as defined by try_globs. + We shall use this cookie for authentication with Launchpad. """ + + # We do not have our cookie. + launchpad_cookiefile = None + # Look in common locations. + try_globs = ('~/.lpcookie.txt', '~/.mozilla/*/*/cookies.sqlite', + '~/.mozilla/*/*/cookies.txt') + + if launchpad_cookiefile == None: + for try_glob in try_globs: + try: + cookiefile = glob.glob(os.path.expanduser(try_glob))[0] + except IndexError: + continue # Unable to glob file - carry on. + # Found: + launchpad_cookiefile = cookiefile + break + + # Unable to find an correct file. + if launchpad_cookiefile == None: + print >> sys.stderr, 'Could not find cookie file for Launchpad " \ + "(looked in " \ %s)' % ", ".join(try_globs) + print >> sys.stderr, 'You should be able to create a valid file by " \ + "logging into Launchpad with Firefox' + sys.exit(1) + + # Found SQLite file. Parse information from it. + if launchpad_cookiefile.find('cookies.sqlite') != -1: + from pysqlite2 import dbapi2 as sqlite + + con = sqlite.connect(launchpad_cookiefile) + + cur = con.cursor() + cur.execute("select host, path, isSecure, expiry, name, value from moz_cookies where host like ?", ['%%launchpad%%']) + + ftstr = ["FALSE", "TRUE"] + + newLPCookie = open("%s/.lpcookie.txt" % os.environ.get('HOME'), 'w') + newLPCookie.write("# HTTP Cookie File.\n") # Header. + + for item in cur.fetchall(): + # Write entries. + newLPCookie.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( + item[0], ftstr[item[0].startswith('.')], item[1], + ftstr[item[2]], item[3], item[4], item[5])) + + newLPCookie.write("\n") # New line. + newLPCookie.close() + launchpad_cookiefile = "%s/.lpcookie.txt" % os.environ.get('HOME') + + print "Using cookie file at: %s." % launchpad_cookiefile + + # Build HTML opener with cookie file. + cj = cookielib.MozillaCookieJar() + cj.load(launchpad_cookiefile) + urlopener = urllib2.build_opener() + urlopener.add_handler(urllib2.HTTPCookieProcessor(cj)) + + return urlopener