diff --git a/debian/changelog b/debian/changelog index f13f93058..50e7d9197 100644 --- a/debian/changelog +++ b/debian/changelog @@ -47,6 +47,8 @@ linux (4.16-1~exp1) UNRELEASED; urgency=medium * debian/lib/python/debian_linux/gencontrol.py: Allow overriding output filenames * debian/lib/python/debian_linux/debian.py: Close changelog after parsing + * debian/lib/python/debian_linux/debian.py: Allow parsing any file as + changelog -- 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 6f40c6222..de8171c0e 100644 --- a/debian/lib/python/debian_linux/debian.py +++ b/debian/lib/python/debian_linux/debian.py @@ -35,26 +35,32 @@ class Changelog(list): self.distribution, self.source, self.version, self.urgency = \ distribution, source, version, urgency - def __init__(self, dir='', version=None): + def __init__(self, dir='', version=None, file=None): if version is None: version = Version - with open(os.path.join(dir, "debian/changelog"), encoding="UTF-8") as 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'))) + if file: + self._parse(version, file) + else: + with open(os.path.join(dir, "debian/changelog"), encoding="UTF-8") as f: + 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'))) class Version(object):