[Pkg-xen-changes] r899 - in trunk/xen-common/debian: bin lib/python/debian_xen

Bastian Blank waldi at alioth.debian.org
Fri Jun 24 18:02:09 UTC 2011


Author: waldi
Date: Fri Jun 24 18:02:08 2011
New Revision: 899

Log:
* debian/bin/genorig.py: Adopt changes from xen package.
* debian/lib/python/debian_xen/debian.py: Update allowed version types.

Modified:
   trunk/xen-common/debian/bin/genorig.py
   trunk/xen-common/debian/lib/python/debian_xen/debian.py

Modified: trunk/xen-common/debian/bin/genorig.py
==============================================================================
--- trunk/xen-common/debian/bin/genorig.py	Fri Jun 24 17:44:58 2011	(r898)
+++ trunk/xen-common/debian/bin/genorig.py	Fri Jun 24 18:02:08 2011	(r899)
@@ -10,6 +10,32 @@
 
 from debian_xen.debian import VersionXen, Changelog
 
+
+class RepoHg(object):
+    def __init__(self, repo, options):
+        self.repo = repo
+        self.tag = options.tag or 'tip'
+
+    def do_archive(self, info):
+        orig_dir = os.path.join(info.temp_dir, info.orig_dir)
+        args = ['hg', 'archive', '-r', self.tag, os.path.realpath(orig_dir)]
+        if info.files:
+            args.extend(itertools.chain(*(('-I', i) for i in info.files)))
+        subprocess.check_call(args, cwd=self.repo)
+
+
+class RepoGit(object):
+    def __init__(self, repo, options):
+        self.repo = repo
+        self.tag = options.tag or 'HEAD'
+
+    def do_archive(self, info):
+        temp_tar = os.path.join(info.temp_dir, 'orig.tar')
+        args = ('git', 'archive', '--prefix', '%s/' % info.orig_dir, '-o', os.path.realpath(temp_tar), self.tag)
+        subprocess.check_call(args, cwd=self.repo)
+        subprocess.check_call(('tar', '-C', info.temp_dir, '-xf', temp_tar))
+
+
 class Main(object):
     log = sys.stdout.write
 
@@ -18,65 +44,61 @@
             'tools/Rules.mk', 'tools/cross-install', 'tools/examples', 'tools/hotplug')
 
     def __init__(self, options, repo):
-        self.options, self.repo = options, repo
+        self.options = options
 
         self.changelog_entry = Changelog(version=VersionXen)[0]
         self.source = self.changelog_entry.source
 
+        if options.version:
+            self.version = options.version
+        else:
+            raise NotImplementedError
+
+        if os.path.exists(os.path.join(repo, '.hg')):
+            self.repo = RepoHg(repo, options)
+        elif os.path.exists(os.path.join(repo, '.git')):
+            self.repo = RepoGit(repo, options)
+        else:
+            raise NotImplementedError
+
+        if options.component:
+            self.orig_dir = options.component
+            self.orig_tar = '%s_%s.orig-%s.tar.gz' % (self.source, self.version, options.component)
+        else:
+            self.orig_dir = '%s-%s' % (self.source, self.version)
+            self.orig_tar = '%s_%s.orig.tar.gz' % (self.source, self.version)
+
     def __call__(self):
         import tempfile
-        self.dir = tempfile.mkdtemp(prefix='genorig', dir='debian')
+        self.temp_dir = tempfile.mkdtemp(prefix='genorig', dir='debian')
         try:
-            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_version(self):
-        if self.options.version:
-            self.version = self.options.version
-            return
-        raise NotImplementedError
+            shutil.rmtree(self.temp_dir)
 
     def do_archive(self):
         self.log("Create archive.\n")
-
-        arg_dir = os.path.join(os.path.realpath(self.dir), self.orig_dir)
-        args = ('hg', 'archive', '-r', self.options.tag, arg_dir) + tuple(itertools.chain(*(('-I', i) for i in self.files)))
-        p = subprocess.Popen(args, cwd=self.repo)
-        if p.wait():
-            raise RuntimeError
-
-    def do_changelog(self):
-        self.log("Exporting changelog.\n")
-
-        log = open("%s/%s/Changelog" % (self.dir, self.orig_dir), 'w')
-        args = ('hg', 'log', '-r', '%s:0' % self.options.tag) + tuple(self.files)
-        p = subprocess.Popen(args, cwd=self.repo, stdout=log)
-        if p.wait():
-            raise RuntimeError
-
-        log.close()
+        self.repo.do_archive(self)
 
     def do_tar(self):
         out = "../orig/%s" % self.orig_tar
         self.log("Generate tarball %s\n" % out)
 
-        p = subprocess.Popen(('tar', '-C', self.dir, '-czf', out, self.orig_dir))
-        if p.wait():
-            raise RuntimeError
+        try:
+            os.stat(out)
+            raise RuntimeError("Destination already exists")
+        except OSError: pass
+
+        subprocess.check_call(('tar', '-C', self.temp_dir, '-czf', out, self.orig_dir))
+
 
 if __name__ == '__main__':
     from optparse import OptionParser
     p = OptionParser(prog=sys.argv[0], usage='%prog [OPTION]... DIR')
-    p.add_option("-t", "--tag", dest="tag", default='tip')
-    p.add_option("-v", "--version", dest="version")
+    p.add_option('-c', '--component', dest='component')
+    p.add_option('-t', '--tag', dest='tag')
+    p.add_option('-v', '--version', dest='version')
     options, args = p.parse_args()
     if len(args) != 1:
         raise RuntimeError

Modified: trunk/xen-common/debian/lib/python/debian_xen/debian.py
==============================================================================
--- trunk/xen-common/debian/lib/python/debian_xen/debian.py	Fri Jun 24 17:44:58 2011	(r898)
+++ trunk/xen-common/debian/lib/python/debian_xen/debian.py	Fri Jun 24 18:02:08 2011	(r899)
@@ -94,15 +94,13 @@
     _version_xen_rules = ur"""
 ^
 (?P<version>
-    (?P<major>\d+)
-    \.\d+
+    \d+\.\d+
 )
 \.\d+
 (?:
-    \+hg
-    (?P<hg_rev>
-        \d+
-    )
+    \+hg\d+
+    |
+    ~rc\d+
 )?
 -
 (?:[^-]+)
@@ -116,8 +114,4 @@
         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()()



More information about the Pkg-xen-changes mailing list