diff options
author | Daniel Dehennin <daniel.dehennin@baby-gnu.org> | 2012-05-30 21:30:45 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-03-29 13:08:23 +0100 |
commit | a9bf9cfd4b31076c54d4e377c1b31b5bd69f8661 (patch) | |
tree | 0df3fdd5a8a7bf006432c4eac1a5048e6f62bbd3 /gbp/deb | |
parent | ea544accfd549d76618a10d831ce7e830fd0785a (diff) |
Move debian/changelog manipulation to gbp.deb.changelog.ChangeLog.
spawn_dch switch gbp.command.wrappers.Command.
* gbp/deb/changelog.py (ChangeLog.spawn_dch): static method adapted from
gbp.scripts.dch and converted to gbp.command_wrappers.Command.
(add_entry): New method adapted from
gbp.scripts.dch.add_changelog_entry.
(add_section): New method adapted from
gbp.scripts.dch.add_changelog_entry. Remove DebianGitRepository and
options, this has nothing to do with changelog management.
* tests/test_Changelog.py: Test new methods.
* gbp/scripts/dch.py: Remove useless functions: system(), spawn_dch(),
add_changelog_section() and add_changelog_entry().
Update calls accordingly.
(fixup_trailer): Use spawn_dch() method of ChangeLog class.
(process_options): dch_options became a list.
(main): Use add_section() and add_entry() methods of ChangeLog object.
Take care of upstream version since ChangeLog.add_section() does not
manage it anymore.
Update exception handling, ChangeLog.spawn_dch() can raise
"CommandExecFailed" exception.
Closes: #672954
Diffstat (limited to 'gbp/deb')
-rw-r--r-- | gbp/deb/changelog.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/gbp/deb/changelog.py b/gbp/deb/changelog.py index b1be400..2d2f016 100644 --- a/gbp/deb/changelog.py +++ b/gbp/deb/changelog.py @@ -19,6 +19,7 @@ import email import os import subprocess +from gbp.command_wrappers import Command class NoChangeLogError(Exception): """No changelog found""" @@ -214,3 +215,98 @@ class ChangeLog(object): Get sections in the changelog """ return list(self.sections_iter) + + @staticmethod + def spawn_dch(msg=[], author=None, email=None, newversion=False, version=None, + release=False, distribution=None, dch_options=[]): + """ + Spawn dch + + @param author: committers name + @type author: C{str} + @param email: committers email + @type email: C{str} + @param newversion: start a new version + @type newversion: C{bool} + @param version: the verion to use + @type version: C{str} + @param release: finalize changelog for releaze + @type release: C{bool} + @param distribution: distribution to use + @type distribution: C{str} + @param dch_options: options passed verbatim to dch + @type dch_options: C{list} + """ + env = {} + args = ['--no-auto-nmu'] + if newversion: + if version: + try: + args.append(version['increment']) + except KeyError: + args.append('--newversion=%s' % version['version']) + else: + args.append('-i') + elif release: + args.extend(["--release", "--no-force-save-on-release"]) + msg = None + + if author and email: + env = {'DEBFULLNAME': author, 'DEBEMAIL': email} + + if distribution: + args.append("--distribution=%s" % distribution) + + args.extend(dch_options) + args.append('--') + if msg: + args.append('[[[insert-git-dch-commit-message-here]]]') + else: + args.append('') + dch = Command('dch', args, extra_env=env) + dch.call([]) + if msg: + old_cl = open("debian/changelog", "r") + new_cl = open("debian/changelog.bak", "w") + for line in old_cl: + if line == " * [[[insert-git-dch-commit-message-here]]]\n": + print >> new_cl, " * " + msg[0] + for line in msg[1:]: + print >> new_cl, " " + line + else: + print >> new_cl, line, + os.rename("debian/changelog.bak", "debian/changelog") + + def add_entry(self, msg, author=None, email=None, dch_options=[]): + """Add a single changelog entry + + @param msg: log message to add + @type msg: C{str} + @param author: name of the author of the log message + @type author: C{str} + @param email: email of the author of the log message + @type email: C{str} + @param dch_options: options passed verbatim to dch + @type dch_options: C{list} + """ + self.spawn_dch(msg=msg, author=author, email=email, dch_options=dch_options) + + def add_section(self, msg, distribution, author=None, email=None, + version={}, dch_options=[]): + """Add a new section to the changelog + + @param msg: log message to add + @type msg: C{str} + @param distribution: distribution to set for the new changelog entry + @type distribution: C{str} + @param author: name of the author of the log message + @type author: C{str} + @param email: email of the author of the log message + @type email: C{str} + @param version: version to set for the new changelog entry + @param version: C{dict} + @param dch_options: options passed verbatim to dch + @type dch_options: C{list} + """ + self.spawn_dch(msg=msg, newversion=True, version=version, author=author, + email=email, distribution=distribution, dch_options=dch_options) |