diff options
author | Bastian Blank <waldi@debian.org> | 2007-01-27 20:56:56 +0000 |
---|---|---|
committer | Bastian Blank <waldi@debian.org> | 2007-01-27 20:56:56 +0000 |
commit | c68949fa25137e3abf2f99956fcc5cc95c07d47b (patch) | |
tree | 42f4e8a189466e8c469fc9fbde2ed75a5c445fbb /debian/lib/python/debian_linux/debian.py | |
parent | 930fd36544ec009cca63fa6de7e7f970004d5907 (diff) | |
download | kernel_replicant_linux-c68949fa25137e3abf2f99956fcc5cc95c07d47b.tar.gz kernel_replicant_linux-c68949fa25137e3abf2f99956fcc5cc95c07d47b.tar.bz2 kernel_replicant_linux-c68949fa25137e3abf2f99956fcc5cc95c07d47b.zip |
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
Diffstat (limited to 'debian/lib/python/debian_linux/debian.py')
-rw-r--r-- | debian/lib/python/debian_linux/debian.py | 117 |
1 files changed, 76 insertions, 41 deletions
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<source> - (?P<version> - (?P<major>\d+\.\d+) - \. +( + (?P<epoch> \d+ ) - (?: - ~ - (?P<modifier> - .+? - ) - )? - (?: - \.dfsg\.\d+ - )? + : +)? +(?P<upstream> + .+? +) +( - (?P<debian>[^-]+) +)? +$ +""" + _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<version> + (?P<major>\d+\.\d+) + \. + \d+ ) +(?: + ~ + (?P<modifier> + .+? + ) +)? +(?: + \.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" |