aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-01-10 15:23:37 +0100
committerGuido Günther <agx@sigxcpu.org>2017-01-10 15:26:37 +0100
commit92f8799fe1e293b6f206721757c7c66f4ededfa6 (patch)
treef2adf87fc0053b0b8d35bb5613aec499f0c21e4b
parent3335bfe1e8fe57945c0ce6ee7f89f144bf54d0ac (diff)
gbp.deb.changelog: Allow to parse out changes from a specific version
We don't iterate over all individual sections but rather let dpkg-parsechangelog do the hard work.
-rw-r--r--gbp/deb/changelog.py14
-rw-r--r--tests/doctests/test_Changelog.py17
2 files changed, 28 insertions, 3 deletions
diff --git a/gbp/deb/changelog.py b/gbp/deb/changelog.py
index 42fcb57..ac867a9 100644
--- a/gbp/deb/changelog.py
+++ b/gbp/deb/changelog.py
@@ -91,9 +91,9 @@ class ChangeLog(object):
self._read()
self._parse()
- def _parse(self):
- """Parse a changelog based on the already read contents."""
- cmd = subprocess.Popen(['dpkg-parsechangelog', '-l-'],
+ def _run_parsechangelog(self, options=None):
+ options = options if options is not None else []
+ cmd = subprocess.Popen(['dpkg-parsechangelog', '-l-'] + options,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
@@ -101,6 +101,11 @@ class ChangeLog(object):
if cmd.returncode:
raise ParseChangeLogError("Failed to parse changelog. "
"dpkg-parsechangelog said:\n%s" % (errors, ))
+ return output
+
+ def _parse(self):
+ """Parse a changelog based on the already read contents."""
+ output = self._run_parsechangelog()
# Parse the result of dpkg-parsechangelog (which looks like
# email headers)
cp = email.message_from_string(output)
@@ -310,3 +315,6 @@ class ChangeLog(object):
"""
self.spawn_dch(msg=msg, newversion=True, version=version, author=author,
email=email, distribution=distribution, dch_options=dch_options)
+
+ def get_changes(self, since='0~'):
+ return self._run_parsechangelog(['-v%s' % since, '-SChanges'])
diff --git a/tests/doctests/test_Changelog.py b/tests/doctests/test_Changelog.py
index 9525e76..cddf5ae 100644
--- a/tests/doctests/test_Changelog.py
+++ b/tests/doctests/test_Changelog.py
@@ -223,6 +223,23 @@ def test_parse_sections():
"""
+def test_get_changes():
+ """
+ Test if we can get changes
+
+ Methods tested:
+ - L{gbp.deb.changelog.ChangeLog.__init__}
+ - L{gbp.deb.changelog.ChangeLog.get_changes}
+
+ >>> import gbp.deb.changelog
+ >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
+ >>> len(cl.get_changes().split('\\n'))
+ 19
+ >>> len(cl.get_changes('0.5.31').split('\\n'))
+ 7
+ """
+
+
def test_add_section():
"""
Test if we can add a section to an existing changelog