"""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"""
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]
"""
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)
>>> cl.date
'Mon, 17 Oct 2011 10:15:22 +0200'
"""
+
+def test_parse_sections():
+ """
+ Test if we can parse sections out of the changelog
+
+ Methods tested:
+ - L{gbp.deb.changelog.ChangeLog.__init__}
+ - L{gbp.deb.changelog.ChangeLogSection.__init__}
+ - L{gbp.deb.changelog.ChangeLogSection.parse}
+
+ Properties tested:
+ - L{gbp.deb.changelog.ChangeLog.sections}
+
+ >>> import gbp.deb.changelog
+ >>> cl = gbp.deb.changelog.ChangeLog(cl_debian)
+ >>> cl.sections[0].package
+ 'git-buildpackage'
+ >>> cl.sections[0].version
+ '0.5.32'
+ >>> cl.sections[1].package
+ 'git-buildpackage'
+ >>> cl.sections[1].version
+ '0.5.31'
+ """