Bastian Blank
2008-Jan-26 23:19 UTC
[Pkg-xen-changes] r516 - in trunk/xen-common/debian: bin lib lib/python lib/python/debian_xen
Author: waldi Date: Sat Jan 26 23:19:10 2008 New Revision: 516 Log: bin/genorig.py, debian/lib/python/debian_xen: Add. Added: trunk/xen-common/debian/bin/ trunk/xen-common/debian/bin/genorig.py (contents, props changed) trunk/xen-common/debian/lib/ trunk/xen-common/debian/lib/python/ trunk/xen-common/debian/lib/python/debian_xen/ trunk/xen-common/debian/lib/python/debian_xen/__init__.py trunk/xen-common/debian/lib/python/debian_xen/debian.py Added: trunk/xen-common/debian/bin/genorig.py =============================================================================--- (empty file) +++ trunk/xen-common/debian/bin/genorig.py Sat Jan 26 23:19:10 2008 @@ -0,0 +1,76 @@ +#!/usr/bin/env python + +import os, os.path, re, shutil, sys + +sys.path.append(sys.path[0] + ''/../lib/python'') + +from debian_xen.debian import VersionXen, Changelog + +class GenOrig(object): + log = sys.stdout.write + + files = [''config'', ''Config.mk'', ''docs/Docs.mk'', ''docs/Makefile'', ''docs/man'', ''tools/Rules.mk'', ''tools/examples''] + + def __init__(self, repo, tag, version): + self.repo, self.tag, self.version = repo, tag, version + + self.changelog_entry = Changelog(version = VersionXen)[0] + self.source = self.changelog_entry.source + + def __call__(self): + import tempfile + self.dir = tempfile.mkdtemp(prefix = ''genorig'', dir = ''debian'') + try: + self.do_update() + self.do_version() + + self.orig_dir = "%s-%s" % (self.source, self.version) + self.orig_tar = "%s_%s.orig.tar.gz" % (self.source, self.version) + + self.do_archive() + self.do_changelog() + self.do_tar() + finally: + shutil.rmtree(self.dir) + + def do_update(self): + if self.tag is None: + return + raise NotImplementedError + + def do_version(self): + if self.version is not None: + return + raise NotImplementedError + + def do_archive(self): + self.log("Create archive.\n") + include_args = '' ''.join((''-I %s'' % i for i in self.files)) + f = os.popen("cd %s; hg archive %s %s/%s" % (self.repo, include_args, os.path.realpath(self.dir), self.orig_dir)) + if f.close() is not None: + raise RuntimeError + + def do_changelog(self): + self.log("Exporting changelog.\n") + file_args = '' ''.join(self.files) + f = os.popen("cd %s; hg log %s" % (self.repo, file_args)) + f_out = file("%s/%s/Changelog" % (self.dir, self.orig_dir), ''w'') + shutil.copyfileobj(f, f_out) + if f.close() is not None: + raise RuntimeError + f_out.close() + + def do_tar(self): + out = "../orig/%s" % self.orig_tar + self.log("Generate tarball %s\n" % out) + f = os.popen("tar -C %s -czf %s %s" % (self.dir, out, self.orig_dir)) + if f.close() is not None: + raise RuntimeError + +if __name__ == ''__main__'': + from optparse import OptionParser + p = OptionParser() + p.add_option("-t", "--tag", dest = "tag") + p.add_option("-v", "--version", dest = "version") + options, args = p.parse_args(sys.argv) + GenOrig(args[1], options.tag, options.version)() Added: trunk/xen-common/debian/lib/python/debian_xen/__init__.py ============================================================================= Added: trunk/xen-common/debian/lib/python/debian_xen/debian.py =============================================================================--- (empty file) +++ trunk/xen-common/debian/lib/python/debian_xen/debian.py Sat Jan 26 23:19:10 2008 @@ -0,0 +1,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()()