summaryrefslogtreecommitdiff
path: root/gbp/deb
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-05-15 21:00:57 +0200
committerGuido Günther <agx@sigxcpu.org>2012-05-15 21:01:33 +0200
commit1eeb298934012223a50ced516c1a38592d30303e (patch)
treeaa137ff36b5dd3a2dabe1215780bfd6422acffb3 /gbp/deb
parentc57d4af675910ec151cf982532db0f877aef413f (diff)
Add gbp.deb.ChangeLogSection
to parse package and version out of a changelog section
Diffstat (limited to 'gbp/deb')
-rw-r--r--gbp/deb/changelog.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/gbp/deb/changelog.py b/gbp/deb/changelog.py
index b8c10b8..7dc51d9 100644
--- a/gbp/deb/changelog.py
+++ b/gbp/deb/changelog.py
@@ -28,6 +28,37 @@ class ParseChangeLogError(Exception):
"""Problem parsing changelog"""
pass
+
+class ChangeLogSection(object):
+ """A section in the changelog describing one particular version"""
+ def __init__(self, package, version):
+ self._package = package
+ self._version = version
+
+ @property
+ def package(self):
+ return self._package
+
+ @property
+ def version(self):
+ return self._version
+
+ @classmethod
+ def parse(klass, section):
+ """
+ Parse one changelog section
+
+ @param section: a changelog section
+ @type section: C{str}
+ @returns: the parse changelog section
+ @rtype: L{ChangeLogSection}
+ """
+ header = section.split('\n')[0]
+ package = header.split()[0]
+ version = header.split()[1][1:-1]
+ return klass(package, version)
+
+
class ChangeLog(object):
"""A Debian changelog"""
@@ -75,6 +106,11 @@ class ChangeLog(object):
raise ParseChangeLogError, output.split('\n')[0]
self._cp = cp
+ if contents:
+ self._contents = contents[:]
+ else:
+ with file(filename) as f:
+ self._contents = f.read()
def __getitem__(self, item):
return self._cp[item]
@@ -148,3 +184,23 @@ class ChangeLog(object):
"""
return self._cp['Date']
+ @property
+ def sections_iter(self):
+ """
+ Iterate over sections in the changelog
+ """
+ section = ''
+ for line in self._contents.split('\n'):
+ if line and line[0] not in [ ' ', '\t' ]:
+ section += line
+ else:
+ if section:
+ yield ChangeLogSection.parse(section)
+ section = ''
+
+ @property
+ def sections(self):
+ """
+ Get sections in the changelog
+ """
+ return list(self.sections_iter)