1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
import re, os
class Changelog(list):
_rules = r"""
^
(?P<source>
\w[-+0-9a-z.]+
)
\
\(
(?P<version>
[^\(\)\ \t]+
)
\)
\s+
(?P<distribution>
[-+0-9a-zA-Z.]+
)
\;
"""
_re = re.compile(_rules, re.X)
class Entry(object):
__slot__ = 'distribution', 'source', 'version'
def __init__(self, distribution, source, version):
self.distribution, self.source, self.version = distribution, source, version
def __init__(self, dir = '', version = None):
if version is None:
version = Version
f = file(os.path.join(dir, "debian/changelog"))
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))
class Version(object):
_version_rules = ur"""
^
(?:
(?P<epoch>
\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.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")
def __str__(self):
return self.complete
@property
def complete(self):
if self.epoch is not None:
return "%d:%s" % (self.epoch, self.complete_noepoch)
return self.complete_noepoch
@property
def complete_noepoch(self):
if self.debian is not None:
return "%s-%s" % (self.upstream, self.debian)
return self.upstream
class VersionXen(Version):
_version_xen_rules = ur"""
^
(?P<version>
(?P<major>\d+)
\.\d+
)
\.\d+
(?:
\+hg
(?P<hg_rev>
\d+
)
)?
-
(?:[^-]+)
$
"""
_version_xen_re = re.compile(_version_xen_rules, re.X)
def __init__(self, version):
super(VersionXen, self).__init__(version)
match = self._version_xen_re.match(version)
if match is None:
raise ValueError("Invalid debian xen version")
d = match.groupdict()
self.xen_major = d['major']
self.xen_version = d['version']
if __name__ == '__main__':
gencontrol()()
|