1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#! /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:
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:
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:
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."
sys.exit(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 not options.quiet:
print "Ubuntu Developers is already set as maintainer."
sys.exit(0)
if 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')
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:
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()
|