Daniel Dehennin <daniel.dehen...@baby-gnu.org> writes: > Daniel Dehennin <daniel.dehen...@baby-gnu.org> writes: > > > [...] > >>> Here[1] is a new version of the patch. >>> >>> The path is splited in 3 parts, nosetests are OK at each steps: >>> >>> 1. Add guess_version_from_upstream() to >>> gbp.deb.git.DebianGitRepository: this is required for next patch >>> >>> 2. Add new methods to gbp.deb.changelog.ChangeLog: they are adapted >>> version of gbp.scripts.dch ones >>> >>> 3. Update gbp.scripts.dch to use new methods. >> >> After rebasing my create-inexistant-changelog patches on this, I figure >> that ChangeLog.add_section() should not manipulate repo object nor >> upstream_tag_format. >> >> I'll redo the patches to solve this point. > > I think it's much better now[1]. > > Changelog methods do not care about DebianGitRepository or options > anymore. > > Thanks, and sorry for the noise.
The patch [3/3] introduce a bug, the CommandExecFailed exception must be qualified. Here is an updated patch [3/3] which use "gbpc.CommandExecFailed" Thanks. From 696cf17e50e0ff8b09d8c7ec66f880686cf9d514 Mon Sep 17 00:00:00 2001 From: Daniel Dehennin <daniel.dehen...@baby-gnu.org> Date: Wed, 30 May 2012 21:39:51 +0200 Subject: [PATCH] Convert gbp.scripts.dch to gbp.deb.changelog.ChangeLog method calls. * gbp/scripts/dch.py: compare_version became useless. Remove useless functions: system(), spawn_dch(), add_changelog_section(), add_changelog_entry() and guess_version_from_upstream(). 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. * tests/03_test_dch_guess_version.py: No more gbp.scripts.dch.guess_version_from_upstream() to test. --- gbp/scripts/dch.py | 140 ++++++------------------------------ tests/03_test_dch_guess_version.py | 54 -------------- 2 files changed, 22 insertions(+), 172 deletions(-) delete mode 100644 tests/03_test_dch_guess_version.py diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index ba96631..96e9533 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -28,7 +28,6 @@ import gbp.dch as dch import gbp.log from gbp.config import GbpOptionParserDebian, GbpOptionGroup from gbp.errors import GbpError -from gbp.deb import compare_versions from gbp.deb.git import GitRepositoryError, DebianGitRepository from gbp.deb.changelog import ChangeLog, NoChangeLogError @@ -36,102 +35,6 @@ user_customizations = {} snapshot_re = re.compile("\s*\*\* SNAPSHOT build @(?P<commit>[a-z0-9]+)\s+\*\*") -def system(cmd): - try: - gbpc.Command(cmd, shell=True)() - except gbpc.CommandExecFailed: - raise GbpError - - -def spawn_dch(msg=[], author=None, email=None, newversion=False, version=None, - release=False, distribution=None, dch_options=''): - """ - Spawn dch - - @param author: committers name - @param email: committers email - @param newversion: start a new version - @param version: the verion to use - @param release: finalize changelog for releaze - @param distribution: distribution to use - @param dch_options: options passed verbatim to dch - """ - distopt = "" - versionopt = "" - env = "" - - if newversion: - if version: - try: - versionopt = version['increment'] - except KeyError: - versionopt = '--newversion=%s' % version['version'] - else: - versionopt = '-i' - elif release: - versionopt = "--release --no-force-save-on-release" - msg = None - - if author and email: - env = """DEBFULLNAME="%s" DEBEMAIL="%s" """ % (author, email) - - if distribution: - distopt = "--distribution=%s" % distribution - - cmd = '%(env)s dch --no-auto-nmu %(distopt)s %(versionopt)s %(dch_options)s ' % locals() - if msg: - cmd += '-- "[[[insert-git-dch-commit-message-here]]]"' - else: - cmd += '-- ""' - system(cmd) - 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_changelog_entry(msg, author, email, dch_options): - """Add a single changelog entry""" - spawn_dch(msg=msg, author=author, email=email, dch_options=dch_options) - - -def guess_version_from_upstream(repo, upstream_tag_format, cp): - """ - Guess the version based on the latest version on the upstream branch - """ - pattern = upstream_tag_format % dict(version='*') - try: - tag = repo.find_tag('HEAD', pattern=pattern) - version = repo.tag_to_version(tag, upstream_tag_format) - if version: - gbp.log.debug("Found upstream version %s." % version) - if cp.has_epoch(): - version = "%s:%s" % (cp.epoch, version) - if compare_versions(version, cp.version) > 0: - return "%s-1" % version - except GitRepositoryError: - gbp.log.debug("No tag found matching pattern %s." % pattern) - return None - - -def add_changelog_section(msg, distribution, repo, options, cp, - author=None, email=None, version={}, dch_options=''): - """Add a new section to the changelog""" - if not version and not cp.is_native(): - v = guess_version_from_upstream(repo, options.upstream_tag, cp) - if v: - version['version'] = v - spawn_dch(msg=msg, newversion=True, version=version, author=author, - email=email, distribution=distribution, dch_options=dch_options) - - def get_author_email(repo, use_git_config): """Get author and email from git configuration""" author = email = None @@ -153,7 +56,7 @@ def fixup_trailer(repo, git_author, dch_options): creating the changelog """ author, email = get_author_email(repo, git_author) - spawn_dch(msg='', author=author, email=email, dch_options=dch_options) + ChangeLog.spawn_dch(msg='', author=author, email=email, dch_options=dch_options) def snapshot_version(version): @@ -294,15 +197,16 @@ def process_options(options, parser): if options.since and options.auto: parser.error("'--since' and '--auto' are incompatible options") + dch_options = [] if options.multimaint_merge: - dch_options = "--multimaint-merge" + dch_options.append("--multimaint-merge") else: - dch_options = "--nomultimaint-merge" + dch_options.append("--nomultimaint-merge") if options.multimaint: - dch_options += " --multimaint" + dch_options.append(" --multimaint") else: - dch_options += " --nomultimaint" + dch_options.append(" --nomultimaint") get_customizations(options.customization_file) return dch_options @@ -472,6 +376,12 @@ def main(argv): else: add_section = False + if add_section and not version_change and not cp.is_native(): + # Get version from upstream if none provided + v = guess_version_from_upstream(repo, options.upstream_tag, cp) + if v: + version['version'] = v + i = 0 for c in commits: i += 1 @@ -485,18 +395,15 @@ def main(argv): if add_section: # Add a section containing just this message (we can't # add an empty section with dch) - add_changelog_section(distribution="UNRELEASED", msg=commit_msg, - version=version_change, - author=commit_author, - email=commit_email, - dch_options=dch_options, - repo=repo, - options=options, - cp=cp) + cp.add_section(distribution="UNRELEASED", msg=commit_msg, + version=version_change, + author=commit_author, + email=commit_email, + dch_options=dch_options) # Adding a section only needs to happen once. add_section = False else: - add_changelog_entry(commit_msg, commit_author, commit_email, dch_options) + cp.add_entry(commit_msg, commit_author, commit_email, dch_options) # Show a message if there were no commits (not even ignored @@ -507,12 +414,9 @@ def main(argv): if add_section: # If we end up here, then there were no commits to include, # so we put a dummy message in the new section. - add_changelog_section(distribution="UNRELEASED", msg=["UNRELEASED"], - version=version_change, - dch_options=dch_options, - repo=repo, - options=options, - cp=cp) + cp.add_section(distribution="UNRELEASED", msg=["UNRELEASED"], + version=version_change, + dch_options=dch_options) fixup_trailer(repo, git_author=options.git_author, dch_options=dch_options) @@ -537,7 +441,7 @@ def main(argv): repo.commit_files([changelog], msg) gbp.log.info("Changelog has been committed for version %s" % version) - except (GbpError, GitRepositoryError, NoChangeLogError), err: + except (gbpc.CommandExecFailed, GbpError, GitRepositoryError, NoChangeLogError), err: if len(err.__str__()): gbp.log.err(err) ret = 1 diff --git a/tests/03_test_dch_guess_version.py b/tests/03_test_dch_guess_version.py deleted file mode 100644 index d954459..0000000 --- a/tests/03_test_dch_guess_version.py +++ /dev/null @@ -1,54 +0,0 @@ -# vim: set fileencoding=utf-8 : - -"""Test L{Changelog}'s guess_version_from_upstream""" - -import unittest - -from gbp.scripts import dch -from gbp.errors import GbpError -from gbp.deb.changelog import ChangeLog -from gbp.deb.git import DebianGitRepository - -class MockGitRepository(object): - def __init__(self, upstream_tag): - self.upstream_tag = upstream_tag - - def find_tag(self, branch, pattern): - return self.upstream_tag - - def tag_to_version(self, tag, format): - return DebianGitRepository.tag_to_version(tag, format) - - -class MockedChangeLog(ChangeLog): - contents = """foo (%s) experimental; urgency=low - - * a important change - - -- Debian Maintainer <ma...@debian.org> Sat, 01 Jan 2012 00:00:00 +0100""" - - def __init__(self, version): - ChangeLog.__init__(self, contents=self.contents % version) - - -class TestGuessVersionFromUpstream(unittest.TestCase): - """Test guess_version_from_upstream""" - def test_guess_no_epoch(self): - """Guess the new version from the upstream tag""" - repo = MockGitRepository(upstream_tag='upstream/1.1') - cp = MockedChangeLog('1.0-1') - guessed = dch.guess_version_from_upstream(repo, - 'upstream/%(version)s', - cp) - self.assertEqual('1.1-1', guessed) - - def test_guess_epoch(self): - """Check if we picked up the epoch correctly (#652366)""" - repo = MockGitRepository(upstream_tag='upstream/1.1') - cp = MockedChangeLog('1:1.0-1') - guessed = dch.guess_version_from_upstream(repo, - 'upstream/%(version)s', - cp) - self.assertEqual('1:1.1-1', guessed) - - -- 1.7.10 -- Daniel Dehennin Récupérer ma clef GPG: gpg --keyserver pgp.mit.edu --recv-keys 0x7A6FE2DF
pgpelpkpsL1QK.pgp
Description: PGP signature