From c68949fa25137e3abf2f99956fcc5cc95c07d47b Mon Sep 17 00:00:00 2001 From: Bastian Blank Date: Sat, 27 Jan 2007 20:56:56 +0000 Subject: debian/bin/gencontrol.py, debian/lib/python/debian_linux/debian.py, debian/lib/python/debian_linux/gencontrol.py: Make version code object oriented. svn path=/dists/trunk/linux-2.6/; revision=8232 --- debian/lib/python/debian_linux/debian.py | 117 ++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 41 deletions(-) (limited to 'debian/lib/python/debian_linux/debian.py') diff --git a/debian/lib/python/debian_linux/debian.py b/debian/lib/python/debian_linux/debian.py index 41817edb81ee..5e1ac3d8d3dd 100644 --- a/debian/lib/python/debian_linux/debian.py +++ b/debian/lib/python/debian_linux/debian.py @@ -1,6 +1,6 @@ import itertools, os.path, re, utils -def read_changelog(dir = ''): +def read_changelog(dir = '', version = None): r = re.compile(r""" ^ ( @@ -22,6 +22,8 @@ def read_changelog(dir = ''): ) ) """, re.VERBOSE) + if version is None: + version = Version f = file(os.path.join(dir, "debian/changelog")) entries = [] while True: @@ -36,58 +38,91 @@ def read_changelog(dir = ''): e = {} e['Distribution'] = match.group('header_distribution') e['Source'] = match.group('header_source') - version = parse_version(match.group('header_version')) - e['Version'] = version + try: + e['Version'] = version(match.group('header_version')) + except Exception: + if not len(entries): + raise + e['Version'] = Version(match.group('header_version')) entries.append(e) return entries -def parse_version(version): - ret = { - 'complete': version, - 'upstream': version, - 'debian': None, - 'linux': None, - } - try: - i = len(version) - version[::-1].index('-') - except ValueError: - return ret - ret['upstream'] = version[:i-1] - ret['debian'] = version[i:] - try: - ret['linux'] = parse_version_linux(version) - except ValueError: - pass - return ret - -def parse_version_linux(version): - version_re = ur""" +class Version(object): + _version_rules = ur""" ^ -(?P - (?P - (?P\d+\.\d+) - \. +( + (?P \d+ ) - (?: - ~ - (?P - .+? - ) - )? - (?: - \.dfsg\.\d+ - )? + : +)? +(?P + .+? +) +( - (?P[^-]+) +)? +$ +""" + _version_re = re.compile(_version_rules, re.X) + + def __init__(self, version): + match = self._version_re.match(version) + if match is None: + raise RuntimeError, "Invalid debian version" + self.complete = version + self.epoch = None + if match.group("epoch") is not None: + self.epoch = int(match.group("epoch")) + self.upstream = match.group("upstream") + self.debian = match.group("debian") + + if self.debian is not None: + self.complete_noepoch = "%s-%s" % (self.upstream, self.debian) + else: + self.complete_noepoch = self.upstream + + def __str__(self): + return self.complete + +class VersionLinux(Version): + _version_linux_rules = ur""" +^ +(?P + (?P\d+\.\d+) + \. + \d+ ) +(?: + ~ + (?P + .+? + ) +)? +(?: + \.dfsg\.\d+ +)? +- +(?:[^-]+) $ """ - match = re.match(version_re, version, re.X) - if match is None: - raise ValueError - return match.groupdict() + _version_linux_re = re.compile(_version_linux_rules, re.X) + def __init__(self, version): + super(VersionLinux, self).__init__(version) + match = self._version_linux_re.match(version) + if match is None: + raise RuntimeError, "Invalid debian linux version" + d = match.groupdict() + self.linux_major = d['major'] + self.linux_modifier = d['modifier'] + self.linux_version = d['version'] + if d['modifier'] is not None: + self.linux_upstream = '-'.join((d['version'], d['modifier'])) + else: + self.linux_upstream = d['version'] + class package_description(object): __slots__ = "short", "long" -- cgit v1.2.3