From 5d31c2426db16c0746699979c6cf632c17b0805d Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Mon, 18 Feb 2013 05:46:00 +0000 Subject: Script to automate debian/changelogs. svn path=/branches/tk377/; revision=5039 --- buildtools/hack-debian-changelog.py | 94 +++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 buildtools/hack-debian-changelog.py (limited to 'buildtools/hack-debian-changelog.py') diff --git a/buildtools/hack-debian-changelog.py b/buildtools/hack-debian-changelog.py new file mode 100644 index 00000000..25f41f88 --- /dev/null +++ b/buildtools/hack-debian-changelog.py @@ -0,0 +1,94 @@ +# $Id$ +# +# Nasty hack to generate debian/changelog entries from subversion. +# This is useful to the extent that it allows us to generate new +# packages automatically with version numbers corresponding to +# subversion revisions; the human-readable part of the changelog may +# or may not be all that useful +# +# +# Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") +# +# 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 ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC 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 debian.changelog +import email.utils +import subprocess +import textwrap +import time +import calendar +import errno + +try: + from lxml.etree import XML +except ImportError: + from xml.etree.ElementTree import XML + +fn = "debian/changelog" + +ignore_trivial_changes = False + +trivial_changes = ("Pull from trunk.", "Merge from trunk.", "Checkpoint.", "Cleanup.") + +changelog = debian.changelog.Changelog() + +try: + with open(fn) as f: + changelog.parse_changelog(f) + latest = int(str(changelog.version).split(".")[1]) + print "Parsed", fn, "latest change", latest +except IOError, e: + if e.errno == errno.ENOENT: + print fn, "not found, starting new changelog" + latest = 0 + else: + raise + +print "Pulling change list from subversion" + +svn = XML(subprocess.check_output(("svn", "log", "--xml", "--revision", "%s:HEAD" % (latest + 1)))) + +first_wrapper = textwrap.TextWrapper(initial_indent = " * ", subsequent_indent = " ") +rest_wrapper = textwrap.TextWrapper(initial_indent = " ", subsequent_indent = " ") + +changed = 0 + +print "Generating new change entries" + +for elt in svn.findall("logentry"): + msg = elt.findtext("msg") + + if ignore_trivial_changes and (msg in trivial_changes or msg + "." in trivial_changes): + continue + + changelog.new_block( + package = changelog.package, + version = "0." + elt.get("revision"), + distributions = changelog.distributions, + urgency = changelog.urgency, + author = elt.findtext("author") + "@rpki.net", + date = email.utils.formatdate(calendar.timegm(time.strptime(elt.findtext("date"), + "%Y-%m-%dT%H:%M:%S.%fZ")))) + changelog.add_change("\n\n".join((rest_wrapper if i else first_wrapper).fill(s) + for i, s in enumerate(msg.split("\n\n")))) + + changed += 1 + +if changed: + print changed, "new entries" + with open(fn + ".new", "w") as f: + print "Writing", f.name + changelog.write_to_open_file(f) +else: + print "No changes" -- cgit v1.2.3 From 9016fc3c7ca5ba922f039c1b67fcf70f7384155a Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Mon, 18 Feb 2013 06:58:51 +0000 Subject: debuild et al are picky about format of email addresses. For some reason debuild now cares about "make test" failing (which it always has on package builds, because of MySQL setup requirements, but debuild used to ignore that), so tweak rules to skip the test suite. svn path=/branches/tk377/; revision=5040 --- buildtools/hack-debian-changelog.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'buildtools/hack-debian-changelog.py') diff --git a/buildtools/hack-debian-changelog.py b/buildtools/hack-debian-changelog.py index 25f41f88..d46ea1d1 100644 --- a/buildtools/hack-debian-changelog.py +++ b/buildtools/hack-debian-changelog.py @@ -41,6 +41,16 @@ ignore_trivial_changes = False trivial_changes = ("Pull from trunk.", "Merge from trunk.", "Checkpoint.", "Cleanup.") +# Fill this in (somehow) with real email addresses if and when we +# care. Right now we only care to the extent that failing to comply +# with the required syntax breaks package builds. + +author_map = {} + +author_default_format = "%s <%s@rpki.net>" + +# Main + changelog = debian.changelog.Changelog() try: @@ -57,7 +67,7 @@ except IOError, e: print "Pulling change list from subversion" -svn = XML(subprocess.check_output(("svn", "log", "--xml", "--revision", "%s:HEAD" % (latest + 1)))) +svn = XML(subprocess.check_output(("svn", "log", "--xml", "--revision", "%s:COMMITTED" % (latest + 1)))) first_wrapper = textwrap.TextWrapper(initial_indent = " * ", subsequent_indent = " ") rest_wrapper = textwrap.TextWrapper(initial_indent = " ", subsequent_indent = " ") @@ -68,16 +78,19 @@ print "Generating new change entries" for elt in svn.findall("logentry"): msg = elt.findtext("msg") + author = elt.findtext("author") if ignore_trivial_changes and (msg in trivial_changes or msg + "." in trivial_changes): continue + author = author_map.get(author, author_default_format % (author, author)) + changelog.new_block( package = changelog.package, version = "0." + elt.get("revision"), distributions = changelog.distributions, urgency = changelog.urgency, - author = elt.findtext("author") + "@rpki.net", + author = author, date = email.utils.formatdate(calendar.timegm(time.strptime(elt.findtext("date"), "%Y-%m-%dT%H:%M:%S.%fZ")))) changelog.add_change("\n\n".join((rest_wrapper if i else first_wrapper).fill(s) -- cgit v1.2.3 From 468123b8c7ccb6c22fb27e051195623444ed031f Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Mon, 18 Feb 2013 07:17:57 +0000 Subject: Install generated debian/changelog, now that we generate ones that debuild accepts. svn path=/branches/tk377/; revision=5041 --- buildtools/hack-debian-changelog.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'buildtools/hack-debian-changelog.py') diff --git a/buildtools/hack-debian-changelog.py b/buildtools/hack-debian-changelog.py index d46ea1d1..01d66fd3 100644 --- a/buildtools/hack-debian-changelog.py +++ b/buildtools/hack-debian-changelog.py @@ -29,6 +29,7 @@ import textwrap import time import calendar import errno +import os try: from lxml.etree import XML @@ -103,5 +104,7 @@ if changed: with open(fn + ".new", "w") as f: print "Writing", f.name changelog.write_to_open_file(f) + print "Renaming %s.new to %s" % (fn, fn) + os.rename(fn + ".new", fn) else: print "No changes" -- cgit v1.2.3