diff --git a/debian/changelog b/debian/changelog index ab01865a6..d7262727a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -52,6 +52,8 @@ linux (4.16-1~exp1) UNRELEASED; urgency=medium * debian/rules.d/tools/lib/lockdep/Makefile: Fix repeated 'make install' * Add template source package to support code signing * Use a dummy build profile for udebs that we test-build before signing + * debian/lib/python/debian_linux/debian.py: Parse bottom lines of changelog + entries -- Roger Shimizu Fri, 23 Mar 2018 21:10:34 +0900 diff --git a/debian/lib/python/debian_linux/debian.py b/debian/lib/python/debian_linux/debian.py index de8171c0e..c15e048b1 100644 --- a/debian/lib/python/debian_linux/debian.py +++ b/debian/lib/python/debian_linux/debian.py @@ -6,7 +6,7 @@ from . import utils class Changelog(list): - _rules = r""" + _top_rules = r""" ^ (?P \w[-+0-9a-z.]+ @@ -25,15 +25,30 @@ class Changelog(list): (?P \w+ ) +\n """ - _re = re.compile(_rules, re.X) + _top_re = re.compile(_top_rules, re.X) + _bottom_rules = r""" +^ +\ --\ +(?P + \S(?:\ ?\S)* +) +\ \ +(?P + (.*) +) +\n +""" + _bottom_re = re.compile(_bottom_rules, re.X) + _ignore_re = re.compile(r'^(?: |\s*\n)') class Entry(object): - __slot__ = 'distribution', 'source', 'version', 'urgency' + __slot__ = 'distribution', 'source', 'version', 'urgency', 'maintainer', 'date' - def __init__(self, distribution, source, version, urgency): - self.distribution, self.source, self.version, self.urgency = \ - distribution, source, version, urgency + def __init__(self, **kwargs): + for key, value in kwargs.items(): + setattr(self, key, value) def __init__(self, dir='', version=None, file=None): if version is None: @@ -45,23 +60,36 @@ class Changelog(list): self._parse(version, f) def _parse(self, version, f): - while True: - line = f.readline() - if not line: - break - match = self._re.match(line) - if not match: - continue - try: - v = version(match.group('version')) - except Exception: - if not len(self): - raise - v = Version(match.group('version')) - self.append(self.Entry(match.group('distribution'), - match.group('source'), v, - match.group('urgency'))) + top_match = None + line_no = 0 + for line in f: + line_no += 1 + + if self._ignore_re.match(line): + pass + elif top_match is None: + top_match = self._top_re.match(line) + if not top_match: + raise Exception('invalid top line %d in changelog' % line_no) + try: + v = version(top_match.group('version')) + except Exception: + if not len(self): + raise + v = Version(top_match.group('version')) + else: + bottom_match = self._bottom_re.match(line) + if not bottom_match: + raise Exception('invalid bottom line %d in changelog' % line_no) + + self.append(self.Entry(distribution=top_match.group('distribution'), + source=top_match.group('source'), + version=v, + urgency=top_match.group('urgency'), + maintainer=bottom_match.group('maintainer'), + date=bottom_match.group('date'))) + top_match = bottom_match = None class Version(object): _version_rules = r"""