update-maintainer: Rewrite completely using python-debian (LP: #666504).

This commit is contained in:
Benjamin Drung 2010-12-25 19:49:49 +01:00
parent 00faea17e2
commit 3f3018aef2
4 changed files with 119 additions and 142 deletions

3
debian/changelog vendored
View File

@ -43,12 +43,13 @@ ubuntu-dev-tools (0.109) UNRELEASED; urgency=low
* Recommend bzr-builddeb (used by sponsor-patch for branches). * Recommend bzr-builddeb (used by sponsor-patch for branches).
* Add most dependencies to Build-Depends for successfully run the tests. * Add most dependencies to Build-Depends for successfully run the tests.
* Recommend python-gnupginterface (used by dgetlp). * Recommend python-gnupginterface (used by dgetlp).
* update-maintainer: Rewrite completely using python-debian (LP: #666504).
[ Michael Vogt ] [ Michael Vogt ]
* add "add-patch" that provides the non-interactive version of * add "add-patch" that provides the non-interactive version of
edit-patch edit-patch
-- Stefano Rivera <stefanor@dvorak.kardiogramm.lan> Fri, 24 Dec 2010 12:16:10 +0200 -- Benjamin Drung <bdrung@ubuntu.com> Sat, 25 Dec 2010 19:47:14 +0100
ubuntu-dev-tools (0.108) experimental; urgency=low ubuntu-dev-tools (0.108) experimental; urgency=low

8
debian/copyright vendored
View File

@ -136,7 +136,6 @@ Files: dch-repeat,
doc/pull-lp-source.1, doc/pull-lp-source.1,
doc/pull-revu-source.1, doc/pull-revu-source.1,
doc/ubuntu-build.1, doc/ubuntu-build.1,
doc/update-maintainer.1,
doc/what-patch.1, doc/what-patch.1,
get-build-deps, get-build-deps,
grep-merges, grep-merges,
@ -151,10 +150,8 @@ Files: dch-repeat,
ubuntutools/lp/lpapicache.py, ubuntutools/lp/lpapicache.py,
ubuntutools/misc.py, ubuntutools/misc.py,
ubuntutools/packages.py, ubuntutools/packages.py,
ubuntutools/update_maintainer.py,
what-patch what-patch
Copyright: 2007, Albin Tonnerre (Lutin) <lut1n.tne@gmail.com> Copyright: 2007-2010, Canonical Ltd.
2007-2010, Canonical Ltd.
2008-2009, Iain Lane <iain@orangesquash.org.uk> 2008-2009, Iain Lane <iain@orangesquash.org.uk>
2006, John Dong <jdong@ubuntu.com> 2006, John Dong <jdong@ubuntu.com>
2009, Jonathan Davies <jpds@ubuntu.com> 2009, Jonathan Davies <jpds@ubuntu.com>
@ -182,6 +179,7 @@ Files: doc/pull-debian-debdiff.1,
doc/sponsor-patch.1, doc/sponsor-patch.1,
doc/suspicious-source.1, doc/suspicious-source.1,
doc/ubuntu-dev-tools.5, doc/ubuntu-dev-tools.5,
doc/update-maintainer.1,
doc/wrap-and-sort.1, doc/wrap-and-sort.1,
pull-debian-debdiff, pull-debian-debdiff,
sponsor-patch, sponsor-patch,
@ -193,10 +191,12 @@ Files: doc/pull-debian-debdiff.1,
ubuntutools/question.py, ubuntutools/question.py,
ubuntutools/sponsor_patch/*, ubuntutools/sponsor_patch/*,
ubuntutools/test/*, ubuntutools/test/*,
ubuntutools/update_maintainer.py,
update-maintainer, update-maintainer,
wrap-and-sort wrap-and-sort
Copyright: 2010, Benjamin Drung <bdrung@ubuntu.com> Copyright: 2010, Benjamin Drung <bdrung@ubuntu.com>
2010, Evan Broder <evan@ebroder.net> 2010, Evan Broder <evan@ebroder.net>
2008, Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
2010, Stefano Rivera <stefanor@ubuntu.com> 2010, Stefano Rivera <stefanor@ubuntu.com>
License: ISC License: ISC
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any

View File

@ -1,10 +1,26 @@
.TH UPDATE\-MAINTAINER "1" "August 04, 2008" "ubuntu-dev-tools" .\" Copyright (c) 2008, Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
.\" 2010, Benjamin Drung <bdrung@ubuntu.com>
.\"
.\" Permission to use, copy, modify, and/or distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.TH UPDATE\-MAINTAINER "1" "December 2010" "ubuntu-dev-tools"
.SH NAME .SH NAME
update\-maintainer \- change the Maintainer field in a Debian source package update\-maintainer \- change the Maintainer field in a Debian source package
.SH SYNOPSIS .SH SYNOPSIS
.B update\-maintainer [\fB\-\-path=<PATH>\fP] [\fB\-\-section=<SECTION>\fP] .B update\-maintainer
[\fIoptions\fR]
.SH DESCRIPTION .SH DESCRIPTION
\fBupdate\-maintainer\fP updates the Maintainer field in the source of \fBupdate\-maintainer\fP updates the Maintainer field in the source of
@ -12,19 +28,20 @@ an Ubuntu package to match the DebianMaintainerField specification.
.SH OPTIONS .SH OPTIONS
.TP .TP
\fB\-\-path=<PATH>\fP \fB\-d \fIPATH\fR, \fB\-\-debian\-directory\fR=\fIPATH\fR
This option allows you to specify the path to the source directory. location of the \fIdebian\fR directory (default: \fB./debian\fR)
.TP .TP
\fB\-\-section=<SECTION>\fP \fB\-h\fR, \fB\-\-help\fR
Manually specify the section of the package. This is necessary if the show a help message and exit
package is not yet in the archive or if you don't have an Internet .TP
connection available when you run \fBupdate\-maintainer\fP. \fB\-q\fR, \fB\-\-quiet\fR
print no informational messages
.SH SEE ALSO .SH SEE ALSO
See https://wiki.ubuntu.com/DebianMaintainerField for more information. See https://wiki.ubuntu.com/DebianMaintainerField for more information.
.SH AUTHOR .SH AUTHOR
\fBupdate-maintainer\fP has been written by Albin Tonnerre <lut1n.tne@gmail.com> \fBupdate-maintainer\fP has been written by Benjamin Drung <bdrung@ubuntu.com>
and this manual page by Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>. and this manual page by Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>.
.PP .PP
Both are released under the GNU General Public License, version 2. Both are released under the ISC license.

View File

@ -1,145 +1,104 @@
# update-maintainer.py - this script is used to update the Maintainer field # update_maintainer.py - updates the Maintainer field of an Ubuntu package
# 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) 2010, Benjamin Drung <bdrung@ubuntu.com>
# #
# Copyright (C) 2009 Jonathan Davies <jpds@ubuntu.com> # Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# #
# Original shell script was: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# Copyright 2007 (C) Albin Tonnerre (Lutin) <lut1n.tne@gmail.com> # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# This program is free software: you can redistribute it and/or modify # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# it under the terms of the GNU General Public License as published by # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# the Free Software Foundation, either version 3 of the License, or # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# (at your option) any later version.
# """This module is for updating the Maintainer field of an Ubuntu package."""
# 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 os
import re
import sys
import ubuntutools.packages import debian.changelog
from ubuntutools.control import Control
from ubuntutools.logger import Logger
# Prior May 2009 these Maintainers were used:
_PREVIOUS_UBUNTU_MAINTAINER = (
"ubuntu core developers <ubuntu-devel-discuss@lists.ubuntu.com>",
"ubuntu motu developers <ubuntu-motu@lists.ubuntu.com>",
)
_UBUNTU_MAINTAINER = "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>"
def _get_distribution(changelog_file):
"""get distribution of latest changelog entry"""
changelog = debian.changelog.Changelog(open(changelog_file))
return changelog.distributions
def update_maintainer(debian_directory, verbose=False): def update_maintainer(debian_directory, verbose=False):
valid_locations = ["debian/control.in", "control.in", "debian/control", """updates the Maintainer field of an Ubuntu package
"control"]
control_file_found = False
# Check changelog file exists. * No modifications are made if the Maintainer field contains an ubuntu.com
for location in valid_locations: email address. Otherwise, the Maintainer field will be set to
if os.path.isfile(location): Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
control_file_found = True * The old value will be saved in a field named XSBC-Original-Maintainer
control_file = location if the Maintainer field is modified.
break # Stop looking.
# Check if we've found a control file. Policy: https://wiki.ubuntu.com/DebianMaintainerField
if not control_file_found: """
sys.stderr.write("Unable to find debian/control file.\n") possible_contol_files = [os.path.join(debian_directory, f) for
return 1 f in ["control", "control.in"]]
# Read found file contents. changelog_file = os.path.join(debian_directory, "changelog")
debian_control_file = open(control_file, "r") control_files = [f for f in possible_contol_files if os.path.isfile(f)]
file_contents = debian_control_file.read()
debian_control_file.close()
# Check if there is a Maintainer field in file found. # Make sure that a changelog and control file is available
if not 'Maintainer' in file_contents: if len(control_files) == 0:
sys.stderr.write("Unable to find Maintainer field in %s.\n" % \ Logger.error("No control file found in %s.", debian_directory)
control_file) return(1)
return 1 if not os.path.isfile(changelog_file):
Logger.error("No changelog file found in %s.", debian_directory)
return(1)
package_field = re.findall('(Source:) (.*)', file_contents) # Strip things like "-proposed-updates" or "-security" from distribution.
package_name = package_field[0][1] distribution = _get_distribution(changelog_file).split("-")[0]
# Get maintainer field information. for control_file in control_files:
maintainer_field = re.findall('(Maintainer:) (.*) (<.*>)', file_contents) control = Control(control_file)
original_maintainer = control.get_maintainer()
# Split out maintainer name and email address. if original_maintainer is None:
maintainer_name = maintainer_field[0][1] Logger.error("No Maintainer field found in %s.", control_file)
maintainer_mail = maintainer_field[0][2] return(1)
if original_maintainer.strip().lower() in _PREVIOUS_UBUNTU_MAINTAINER:
if verbose:
print "The old maintainer was: %s" % original_maintainer
print "Resetting as: %s" % _UBUNTU_MAINTAINER
control.set_original_maintainer(_UBUNTU_MAINTAINER)
control.save()
continue
if original_maintainer.strip().endswith("ubuntu.com>"):
if verbose:
print ("The Maintainer email is set to an ubuntu.com address. "
"Doing nothing.")
continue
if distribution in ("stable", "testing", "unstable", "experimental"):
if verbose:
print "The package targets Debian. Doing nothing."
return(0)
if control.get_original_maintainer() is not None:
print "Overwriting original maintainer: %s" % \
control.get_original_maintainer()
if maintainer_mail.endswith("@ubuntu.com>"):
if verbose: if verbose:
print "Maintainer email is set to an @ubuntu.com address - doing nothing." print "The original maintainer is: %s" % original_maintainer
return 0 print "Resetting as: %s" % _UBUNTU_MAINTAINER
control.set_original_maintainer(original_maintainer)
control.set_maintainer(_UBUNTU_MAINTAINER)
control.save()
# Prior May 2009 these Maintainers were used: return(0)
# main or restricted: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
# universe or multiverse: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
old_maintainer = maintainer_mail in ("<ubuntu-devel-discuss@lists.ubuntu.com>",
"<ubuntu-motu@lists.ubuntu.com>")
if maintainer_mail.endswith("@lists.ubuntu.com>") and not old_maintainer:
if verbose:
print "Maintainer email is set to an @lists.ubuntu.com address - doing nothing."
return 0
# Check if Maintainer field is as approved in TB decision.
if 'Ubuntu Developers' in maintainer_name and \
'<ubuntu-devel-discuss@lists.ubuntu.com>' in maintainer_mail:
if verbose:
print "Ubuntu Developers is already set as maintainer."
return 0
if not old_maintainer and \
not (ubuntutools.packages.checkIsInDebian(package_name, 'unstable') or \
ubuntutools.packages.checkIsInDebian(package_name, 'experimental')):
user_email_address = os.getenv('DEBEMAIL')
if not user_email_address:
user_email_address = os.getenv('EMAIL')
if not user_email_address:
sys.stderr.write('The environment variable DEBEMAIL or ' + \
'EMAIL needs to be set to make proper use ' + \
'of this script.\n')
return 1
user_name = os.getenv('DEBFULLNAME')
if not user_name:
sys.stderr.write('The environment variable DEBFULLNAME needs ' + \
'to be set to make proper use of this script.\n')
return 1
target_maintainer = user_name + ' <' + user_email_address + '>'
else:
target_maintainer = "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>"
# Set original maintainer field in a string.
original_maintainer = maintainer_name + " " + maintainer_mail
# If maintainer-field contained the pre-archive-reorganisation entries,
# don't add a new XSBC-Original maintainer field
if not "lists.ubuntu.com" in original_maintainer:
# Remove existing Original-Maintainer field
# to avoid multiple Original-Maintainer fields
original_maintainer_fields = re.findall('(.*Original-Maintainer): (.*)',
file_contents)
if len(original_maintainer_fields) > 0:
for original_maintainer_field in original_maintainer_fields:
if verbose:
print "Removing existing %s: %s" % original_maintainer_field
file_contents = re.sub('.*Original-Maintainer: .*\n', "",
file_contents)
final_addition = "Maintainer: " + target_maintainer + \
"\nXSBC-Original-Maintainer: " + original_maintainer
else:
final_addition = "Maintainer: " + target_maintainer
if verbose:
print "The original maintainer for this package is: " + original_maintainer
print "Resetting as: " + target_maintainer
# Replace text.
debian_control_file = open(control_file, "w")
original_maintainer_line = "Maintainer: " + original_maintainer
debian_control_file.write(re.sub(re.escape(original_maintainer_line),
final_addition, file_contents))
debian_control_file.close()
return 0