diff --git a/debian/copyright b/debian/copyright index 45f4cea..2745430 100644 --- a/debian/copyright +++ b/debian/copyright @@ -154,7 +154,6 @@ Files: dch-repeat, ubuntutools/misc.py, ubuntutools/packages.py, ubuntutools/update_maintainer.py, - update-maintainer, what-patch Copyright: 2007, Albin Tonnerre (Lutin) 2007-2010, Canonical Ltd. @@ -193,6 +192,7 @@ Files: doc/sponsor-patch.1, ubuntutools/question.py, ubuntutools/sponsor_patch/*, ubuntutools/test/*, + update-maintainer, wrap-and-sort Copyright: 2010, Benjamin Drung 2010, Evan Broder diff --git a/ubuntutools/control.py b/ubuntutools/control.py index 6908335..06a3899 100644 --- a/ubuntutools/control.py +++ b/ubuntutools/control.py @@ -1,4 +1,3 @@ -# # control.py - Represents a debian/control file # # Copyright (C) 2010, Benjamin Drung @@ -15,10 +14,27 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +"""This module implements facilities to deal with Debian control.""" + import os import debian.deb822 +def _insert_after(paragraph, item_before, new_item, new_value): + """Insert new_item into directly after item_before + + New items added to a dictionary are appended.""" + item_found = False + for item in paragraph: + if item_found: + value = paragraph.pop(item) + paragraph[item] = value + if item == item_before: + item_found = True + paragraph[new_item] = new_value + if not item_found: + paragraph[new_item] = new_value + class Control(object): """Represents a debian/control file""" @@ -30,12 +46,13 @@ class Control(object): for paragraph in debian.deb822.Deb822.iter_paragraphs(sequence): self.paragraphs.append(paragraph) - def get_source_paragraph(self): - """Returns the source paragraph of the control file.""" - if self.paragraphs: - return self.paragraphs[0] - else: - return None + def get_maintainer(self): + """Returns the value of the Maintainer field.""" + return self.paragraphs[0].get("Maintainer") + + def get_original_maintainer(self): + """Returns the value of the XSBC-Original-Maintainer field.""" + return self.paragraphs[0].get("XSBC-Original-Maintainer") def save(self, filename=None): """Saves the control file.""" @@ -46,6 +63,18 @@ class Control(object): control_file.write(content.encode("utf-8")) control_file.close() + def set_maintainer(self, maintainer): + """Sets the value of the Maintainer field.""" + self.paragraphs[0]["Maintainer"] = maintainer + + def set_original_maintainer(self, original_maintainer): + """Sets the value of the XSBC-Original-Maintainer field.""" + if "XSBC-Original-Maintainer" in self.paragraphs[0]: + self.paragraphs[0]["XSBC-Original-Maintainer"] = original_maintainer + else: + _insert_after(self.paragraphs[0], "Maintainer", + "XSBC-Original-Maintainer", original_maintainer) + def strip_trailing_spaces(self): """Strips all trailing spaces from the control file.""" for paragraph in self.paragraphs: diff --git a/ubuntutools/sponsor_patch/main.py b/ubuntutools/sponsor_patch/main.py index 7c6dcf9..1574071 100644 --- a/ubuntutools/sponsor_patch/main.py +++ b/ubuntutools/sponsor_patch/main.py @@ -26,7 +26,7 @@ import debian.changelog import debian.deb822 import launchpadlib.launchpad -import ubuntutools.update_maintainer +from ubuntutools.update_maintainer import update_maintainer from ubuntutools.logger import Logger from ubuntutools.question import Question, YesNoQuestion, input_number @@ -289,7 +289,7 @@ def main(bug_number, build, builder, edit, keyid, lpinstance, update, upload, # update the Maintainer field Logger.command(["update-maintainer"]) - if ubuntutools.update_maintainer.update_maintainer(verbose) != 0: + if update_maintainer("debian", verbose) != 0: Logger.error("update-maintainer script failed.") sys.exit(1) diff --git a/ubuntutools/update_maintainer.py b/ubuntutools/update_maintainer.py index 1e8784a..96281f2 100644 --- a/ubuntutools/update_maintainer.py +++ b/ubuntutools/update_maintainer.py @@ -29,7 +29,7 @@ import sys import ubuntutools.packages -def update_maintainer(verbose=False): +def update_maintainer(debian_directory, verbose=False): valid_locations = ["debian/control.in", "control.in", "debian/control", "control"] control_file_found = False diff --git a/update-maintainer b/update-maintainer index 4625887..8914ff2 100755 --- a/update-maintainer +++ b/update-maintainer @@ -1,43 +1,43 @@ -#! /usr/bin/python +#!/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: +# Copyright (C) 2010, Benjamin Drung # -# 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 . +# 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. import optparse import os import sys -import ubuntutools.update_maintainer +from ubuntutools.update_maintainer import update_maintainer -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() +def main(): + 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("-d", "--debian-directory", dest="debian_directory", + help="location of the 'debian' directory (default: " + "%default).", metavar="PATH", default="./debian") + parser.add_option("-q", "--quiet", help="print no informational messages", + dest="quiet", action="store_true", default=False) + (options, args) = parser.parse_args() -sys.exit(ubuntutools.update_maintainer.update_maintainer(not options.quiet)) + if len(args) != 0: + print >> sys.stderr, ("%s: Error: Unsupported additional parameters " + "specified: %s") % (script_name, ", ".join(args)) + sys.exit(1) + + sys.exit(update_maintainer(options.debian_directory, not options.quiet)) + +if __name__ == "__main__": + main()