mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-11-04 07:54:03 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			167 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			167 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/python
 | 
						|
# 
 | 
						|
#   buildd - command line interface for Launchpad buildd operations.
 | 
						|
#
 | 
						|
#   Copyright (C) 2007 Canonical Ltd.
 | 
						|
#   Authors:
 | 
						|
#    - Martin Pitt <martin.pitt@canonical.com>
 | 
						|
#    - Jonathan Patrick Davies <jpds@ubuntu.com>
 | 
						|
#
 | 
						|
#   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 <http://www.gnu.org/licenses/>.
 | 
						|
#
 | 
						|
 | 
						|
import os
 | 
						|
import re
 | 
						|
import sys
 | 
						|
import urllib2
 | 
						|
from optparse import OptionGroup
 | 
						|
from optparse import OptionParser
 | 
						|
from urllib import urlencode
 | 
						|
 | 
						|
sys.path.append("/usr/share/ubuntu-dev-tools/")
 | 
						|
import common
 | 
						|
 | 
						|
# Usage.
 | 
						|
usage = "%prog <srcpackage> <release> <operation>\n\n"
 | 
						|
usage += "Where operation may be one of: rescore, retry, or status.\n"
 | 
						|
usage += "Only Launchpad Buildd Admins may rescore package builds."
 | 
						|
 | 
						|
# Prepare our option parser.
 | 
						|
optParser = OptionParser(usage)
 | 
						|
 | 
						|
# Retry options 
 | 
						|
retryRescoreOptions = OptionGroup(optParser, "Retry and rescore options",
 | 
						|
    "These options may only be used with the 'retry' and 'rescore' operations.")
 | 
						|
retryRescoreOptions.add_option("-a", "--arch", type = "string",
 | 
						|
    action = "store", dest = "architecture",
 | 
						|
    help = "Rebuild or rescore a specific architecture.")
 | 
						|
 | 
						|
# Add the retry options to the main group.
 | 
						|
optParser.add_option_group(retryRescoreOptions)
 | 
						|
 | 
						|
# Parse our options.
 | 
						|
(options, args) = optParser.parse_args()
 | 
						|
 | 
						|
# Check we have the correct number of arguments.
 | 
						|
if len(args) < 3:
 | 
						|
    optParser.error("Incorrect number of arguments.")
 | 
						|
 | 
						|
package = str(args[0]).lower()
 | 
						|
release = str(args[1]).lower()
 | 
						|
op      = str(args[2]).lower()
 | 
						|
 | 
						|
# Check our operation.
 | 
						|
if op not in ("rescore", "retry", "status"):
 | 
						|
    print >> sys.stderr, "Invalid operation: %s." % op
 | 
						|
    sys.exit(1)
 | 
						|
 | 
						|
# If the user has specified an architecture to build, we only wish to rebuild it
 | 
						|
# and nothing else.
 | 
						|
if op not in ("retry", 'rescore') and options.architecture:
 | 
						|
    print >> sys.stderr, "Operation %s does not use the --arch option." % op
 | 
						|
    sys.exit(1)
 | 
						|
elif op in ("retry", "rescore") and options.architecture:
 | 
						|
    if options.architecture not in ("armel", "amd64", "hppa", "i386", "ia64", 
 | 
						|
	        "lpia", "powerpc", "sparc"):
 | 
						|
        print >> sys.stderr, "Invalid architecture specified: %s." % options.architecture
 | 
						|
        sys.exit(1)
 | 
						|
    else:
 | 
						|
        oneArch = True
 | 
						|
else:
 | 
						|
    oneArch = False
 | 
						|
 | 
						|
# Prepare Launchpad cookie.
 | 
						|
launchpadCookie = common.prepareLaunchpadCookie()
 | 
						|
urlopener = common.setupLaunchpadUrlOpener(launchpadCookie)
 | 
						|
 | 
						|
# Check the release exists.
 | 
						|
common.checkReleaseExists(release)
 | 
						|
 | 
						|
# Find out the version in given release.
 | 
						|
(page, version) = common.checkSourceExists(package, release)
 | 
						|
 | 
						|
# Get the component the package is in.
 | 
						|
component = common.packageComponent(package, release)
 | 
						|
 | 
						|
# Output details.
 | 
						|
print "The source version for '%s' in %s (%s) is at %s." % (package,
 | 
						|
    release.capitalize(), component, 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()
 | 
						|
release = release.split('-')[0] # strip off pocket
 | 
						|
 | 
						|
print "Current build status for this package is as follows:"
 | 
						|
 | 
						|
for m in re.finditer('"/ubuntu/\+source/%s/%s(/\+build/\d+)"[^\n]+\n\s*(\w+).*?<span>(\w+)</span>.*?</a>\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)
 | 
						|
 | 
						|
# Operations that are remaining may only be done by Ubuntu developers (retry)
 | 
						|
# or buildd admins (rescore). Check if the proper permissions are in place.
 | 
						|
if op == "rescore": teamNeeded = "launchpad-buildd-admins"
 | 
						|
if op == "retry":
 | 
						|
    if component in ("main", "restricted"):
 | 
						|
        teamNeeded = "ubuntu-core-dev"
 | 
						|
    else:
 | 
						|
        teamNeeded = "ubuntu-dev"
 | 
						|
 | 
						|
necessaryPrivs = common.isLPTeamMember(teamNeeded)
 | 
						|
 | 
						|
if not necessaryPrivs:
 | 
						|
    print >> sys.stderr, "You cannot perform the %s operation on a %s package " \
 | 
						|
        "as you are not member of the '%s' team on Launchpad." % (op, component,
 | 
						|
            teamNeeded)
 | 
						|
    print "Should this be incorrect, please log in to Launchpad using Firefox, " \
 | 
						|
        "delete the ~/.lpcookie.txt file and rerun this script."
 | 
						|
    sys.exit(1)
 | 
						|
 | 
						|
for build, (arch, status) in buildstats.iteritems():
 | 
						|
    if oneArch and not options.architecture == arch:
 | 
						|
        # Skip this architecture.
 | 
						|
        continue
 | 
						|
 | 
						|
    if op in ('rescore'):
 | 
						|
        if status in ('Needs building'):
 | 
						|
            print 'Rescoring', build, '(%s).' % arch
 | 
						|
 | 
						|
            try:
 | 
						|
                urlopener.open(build + '/+rescore', urlencode(
 | 
						|
                    {'field.priority': '5000', 'field.actions.rescore': '1'}))
 | 
						|
            except:
 | 
						|
                print >> sys.stderr, "Unable to request rescore on %s." % arch
 | 
						|
        else:
 | 
						|
            print "Not rescoring on %s; status is: %s." % (arch, status.lower())
 | 
						|
    
 | 
						|
    if op in ('retry'): # Retry requested.
 | 
						|
        if status in ('Failed to build', 'Chroot problem', 'Failed to upload'):
 | 
						|
            print 'Retrying:', build, '(%s).' % arch
 | 
						|
 | 
						|
            try:
 | 
						|
                urlopener.open(build + '/+retry', urlencode(
 | 
						|
                    {'RETRY': '1'}))
 | 
						|
            except: # Error encountered while submitting request.
 | 
						|
                print >> sys.stderr, "Unable to request retry on %s." % arch
 | 
						|
        else: # The package does not require rebuilding.
 | 
						|
            print "Not retrying on %s; status is %s." % (arch, status.lower())
 |