ubuntu-dev-tools/update-maintainer

135 lines
5.0 KiB
Plaintext
Raw Normal View History

#! /usr/bin/python
#
# 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 <jpds@ubuntu.com>
#
# Original shell script was:
#
# Copyright 2007 (C) Albin Tonnerre (Lutin) <lut1n.tne@gmail.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 optparse
import os
import re
import sys
import ubuntutools.packages
script_name = os.path.basename(sys.argv[0])
usage = "%s [options]" % (script_name)
epilog = "See %s(1) for more info." % (script_name)
parser = optparse.OptionParser(usage=usage, epilog=epilog)
parser.add_option("-q", "--quiet", help="print no informational messages",
dest="quiet", action="store_true", default=False)
(options, args) = parser.parse_args()
valid_locations = ["debian/control.in", "control.in", "debian/control", "control"]
control_file_found = False
# Check changelog file exists.
for location in valid_locations:
2010-06-03 21:37:56 +02:00
if os.path.exists(location):
control_file_found = True
control_file = location
break # Stop looking.
# Check if we've found a control file.
if not control_file_found:
2010-06-03 21:37:56 +02:00
sys.stderr.write("Unable to find debian/control file.\n")
sys.exit(1)
# Read found file contents.
debian_control_file = open(control_file, "r")
file_contents = debian_control_file.read()
debian_control_file.close()
# Check if there is a Maintainer field in file found.
if not 'Maintainer' in file_contents:
2010-06-03 21:37:56 +02:00
sys.stderr.write("Unable to find Maintainer field in %s.\n" % control_file)
sys.exit(1)
package_field = re.findall('(Source:) (.*)', file_contents)
package_name = package_field[0][1]
# Get maintainer field information.
maintainer_field = re.findall('(Maintainer:) (.*) (<.*>)', file_contents)
# Split out maintainer name and email address.
maintainer_name = maintainer_field[0][1]
maintainer_mail = maintainer_field[0][2]
if maintainer_mail.find("@ubuntu.com") != -1:
if not options.quiet:
print "Maintainer email is set to an @ubuntu.com address - doing nothing."
2010-06-03 21:37:56 +02:00
sys.exit(0)
# Check if Maintainer field is as approved in TB decision.
if 'Ubuntu Developers' in maintainer_name and \
2010-06-03 21:37:56 +02:00
'<ubuntu-devel-discuss@lists.ubuntu.com>' in maintainer_mail:
if not options.quiet:
print "Ubuntu Developers is already set as maintainer."
2010-06-03 21:37:56 +02:00
sys.exit(0)
if not (ubuntutools.packages.checkIsInDebian(package_name, 'unstable') or ubuntutools.packages.checkIsInDebian(package_name, 'experimental')):
2010-06-03 21:37:56 +02:00
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')
sys.exit(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')
sys.exit(1)
target_maintainer = user_name + ' <' + user_email_address + '>'
else:
2010-06-03 21:37:56 +02:00
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 not options.quiet:
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 not options.quiet:
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()