From 6a17e7c6c7a00fce3303002b225c6e9b2b462a89 Mon Sep 17 00:00:00 2001 From: Jonathan Davies Date: Sun, 31 May 2009 21:45:35 +0100 Subject: [PATCH] * ubuntutools/packages.py: Created checkIsInDebian() function. * requestsync: Adapt to use new function above. * update-maintainer: Rewrote in Python and adapted to use Maintainer field spec approved by the Technical Board at: - https://lists.ubuntu.com/archives/ubuntu-devel/2009-May/028213.html --- requestsync | 14 +-- ubuntutools/packages.py | 14 +++ update-maintainer | 187 +++++++++++++++++----------------------- 3 files changed, 99 insertions(+), 116 deletions(-) diff --git a/requestsync b/requestsync index d171f3c..742a39a 100755 --- a/requestsync +++ b/requestsync @@ -42,6 +42,7 @@ import ubuntutools.lp.libsupport as lp_libsupport import ubuntutools.lp.udtexceptions as udtexceptions # https_proxy fix import ubuntutools.common +import ubuntutools.packages launchpad_cookiefile = lp_cookie.prepareLaunchpadCookie() @@ -138,17 +139,10 @@ def cur_version_component(sourcepkg, release): def cur_deb_version(sourcepkg, distro): '''Return the current debian version of a package in a Debian distro.''' - madison = subprocess.Popen(['rmadison', '-u', 'debian', '-a', 'source', \ - '-s', distro, sourcepkg], \ - stdout=subprocess.PIPE) - out = madison.communicate()[0] - assert (madison.returncode == 0) - - try: - assert out - except AssertionError: + if not ubuntutools.packages.checkIsInDebian(sourcepkg, distro): print "%s doesn't appear to exist in Debian." % sourcepkg - sys.exit(1) + sys.exit(0) + # Work-around for a bug in Debians madison.php script not returning # only the source line for line in out.splitlines(): diff --git a/ubuntutools/packages.py b/ubuntutools/packages.py index 5491d4b..d3e37ec 100644 --- a/ubuntutools/packages.py +++ b/ubuntutools/packages.py @@ -101,3 +101,17 @@ def packageComponent(package, release): component = rel.split('/')[1] return component.strip() + +def checkIsInDebian(package, distro): + madison = subprocess.Popen(['rmadison', '-u', 'debian', '-a', 'source', \ + '-s', distro, package], \ + stdout=subprocess.PIPE) + out = madison.communicate()[0] + assert (madison.returncode == 0) + + try: + assert out + except AssertionError: + out = False + + return out diff --git a/update-maintainer b/update-maintainer index b23ead7..c5faa0b 100755 --- a/update-maintainer +++ b/update-maintainer @@ -1,120 +1,95 @@ -#!/bin/sh -# -# Copyright 2007 (C) Albin Tonnerre (Lutin) -# -# ################################################################## -# -# 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; version 2. +#! /usr/bin/python # -# 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. -# -# See file /usr/share/common-licenses/GPL-2 for more details. +# update-maintainer - this script is used to update the Maintainer field of an +# Ubuntu package, as approved by the Ubuntu Technical +# Board at: # -# ################################################################## +# https://lists.ubuntu.com/archives/ubuntu-devel/2009-May/028213.html +# +# Copyright (C) 2009 Jonathan Davies +# +# Original shell script was: +# +# Copyright 2007 (C) Albin Tonnerre (Lutin) +# +# 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 . # -# This script is used to update the Maintainer field of an Ubuntu package -# to match the DebianMaintainerField specification. -usage() { -cat <&2; exit 1; } -while :; do - case $1 in - --path) - path="$2" - shift 2 - ;; - --section) - [ "$2" != "main" ] && - [ "$2" != "restricted" ] && - [ "$2" != "universe" ] && - [ "$2" != "multiverse" ] && echo "Invalid section. Valid sections: main restricted universe multiverse" >&2 && exit 1 - section="$2" - shift 2 - ;; - --help) - usage - exit 0 - ;; - --) - shift - break - ;; - *) - echo "Bad parameter." - usage >&2 - exit 1 - ;; - esac -done +valid_locations = ["debian/control", "control"] +control_file_found = False -cd ${path-.} +# Check changelog file exists. +for location in valid_locations: + if os.path.exists(location): + control_file_found = True + control_file = location + break # Stop looking. -# look for the debian directory -if [ -f debian/control ] && [ -f debian/changelog ]; then - DEBIANDIR=debian -elif [ -f control ] && [ -f changelog ]; then - DEBIANDIR=. -else - echo "Please execute «$0» in the source folder." >&2 - exit 1 -fi +# Check if we've found a control file. +if not control_file_found: + sys.stderr.write("Unable to find debian/control file.\n") + sys.exit(1) -if [ ! -r $DEBIANDIR/changelog ] -then - echo "Make sure that the changelog file is readable." >&2 && exit 1 -fi +# Read found file contents. +debian_control_file = open(control_file, "r") +file_contents = debian_control_file.read() +debian_control_file.close() -for file in control control.in control.real; do - if [ -f $DEBIANDIR/$file ]; then - if [ ! -r $DEBIANDIR/$file ] || [ ! -w $DEBIANDIR/$file ]; then - echo "Make sure that the control file(s) is (are) readable and writable." >&2 && exit 1 - fi - controls="$controls $file" - fi -done +# Check if there is a Maintainer field in file found. +if not 'Maintainer' in file_contents: + sys.stderr.write("Unable to find Maintainer field in %s.\n" % control_file) + sys.exit(1) -if ! head -1 $DEBIANDIR/changelog | grep -q '(*ubuntu.*)' -then - echo "Latest changelog entry has no Ubuntu version number." >&2 - exit 1 -fi +package_field = re.findall('(Source:) (.*)', file_contents) +package_name = package_field[0][1] -if grep -E "^Maintainer: .*@.*ubuntu.*>" $DEBIANDIR/control >/dev/null -then - echo "Package already maintained by the Ubuntu team." >&2 - exit 1 -fi +# Get maintainer field information. +maintainer_field = re.findall('(Maintainer:) (.*) (<.*>)', file_contents) -if [ -z "$section" ]; then - DISTRO=$(sed -r '1!d;s/.*\) (.*);.*/\1/' $DEBIANDIR/changelog | cut -d'-' -f1) - pkgline=$(rmadison -u ubuntu -a source -s $DISTRO $(head -1 $DEBIANDIR/changelog | cut -d' ' -f1)) - if [ -z "$pkgline" ]; then - echo "The package doesn't exist in the $DISTRO archive. You may have to use the" >&2 - echo "--section argument. Run $0 --help for more information." >&2 - exit 1 - fi - section=$(echo $pkgline | grep -Eo "main|universe|multiverse|restricted") || section=main -fi +# Split out maintainer name and email address. +maintainer_name = maintainer_field[0][1] +maintainer_mail = maintainer_field[0][2] -case $section in - "main"|"restricted") email="Ubuntu Core Developers " ;; - "universe"|"multiverse") email="Ubuntu MOTU Developers " ;; - *) echo "No section found for this package; aborting" >&2; exit 1 ;; -esac +# Check if Maintainer field is as approved in TB decision. +if 'Ubuntu Developers' in maintainer_name and \ + '' in maintainer_mail: + print "Ubuntu Developers is already set as maintainer." + sys.exit(0) -for file in $controls; do - sed -ri "s/(^Maintainer:) (.*)/\1 $email\nXSBC-Original-\1 \2/" $DEBIANDIR/$file -done +if not ubuntutools.packages.checkIsInDebian(package_name, 'unstable'): + user_email_address = os.getenv('DEBEMAIL') + if not user_email_address: + sys.stderr.write('The environment variable DEBEMAIL needs to be ' +\ + 'set to make proper use of this script.\n') + sys.exit(1) + target_maintainer = user_email_address +else: + target_maintainer = "Ubuntu Developers " + +# Set original maintainer field in a string. +original_maintainer = maintainer_name + " " + maintainer_mail +final_addition = target_maintainer + "\nXSBC-Original-Maintainer: " + original_maintainer + +print "The original maintainer for this package is: " + original_maintainer +print "Resetting as: " + target_maintainer + +# Replace text. +debian_control_file = open(control_file, "w") +debian_control_file.write(re.sub(original_maintainer, final_addition, file_contents)) +debian_control_file.close()