Move DpkgCompareVersions and add compare_versions
authorGuido Günther <agx@sigxcpu.org>
Thu, 12 Aug 2010 20:05:40 +0000 (22:05 +0200)
committerGuido Günther <agx@sigxcpu.org>
Thu, 12 Aug 2010 20:06:08 +0000 (22:06 +0200)
Git-Dch: Ignore

gbp/deb.py
git-import-dscs

index 0663977..93173be 100644 (file)
@@ -32,6 +32,31 @@ class ParseChangeLogError(Exception):
     """problem parsing changelog"""
     pass
 
+
+class DpkgCompareVersions(gbpc.Command):
+    cmd='/usr/bin/dpkg'
+
+    def __init__(self):
+        if not os.access(self.cmd, os.X_OK):
+            raise GbpError, "%s not found - cannot use compare versions" % self.cmd
+        gbpc.Command.__init__(self, self.cmd, ['--compare-versions'])
+
+    def __call__(self, version1, version2):
+        self.run_error = "Couldn't compare %s with %s" % (version1, version2)
+        res = gbpc.Command.call(self, [ version1, 'lt', version2 ])
+        if res not in [ 0, 1 ]:
+            raise gbpc.CommandExecFailed, "%s: bad return code %d" % (self.run_error, res)
+        if res == 0:
+            return -1
+        elif res == 1:
+            res = gbpc.Command.call(self, [ version1, 'gt', version2 ])
+            if res not in [ 0, 1 ]:
+                raise gbpc.CommandExecFailed, "%s: bad return code %d" % (self.run_error, res)
+            if res == 0:
+                return 1
+        return 0
+
+
 class DscFile(object):
     """Keeps all needed data read from a dscfile"""
     compressions = r"(gz|bz2)"
@@ -215,7 +240,9 @@ def symlink_orig(cp, compression, orig_dir, output_dir, force=False):
         return False
     return True
 
+
 def do_uscan():
+    """invoke uscan to fetch a new upstream version"""
     p = subprocess.Popen(['uscan', '--dehs'], stdout=subprocess.PIPE)
     out = p.communicate()[0].split('\n')
     if "<status>up to date</status>" in out:
@@ -242,6 +269,7 @@ def do_uscan():
                 return (True, None)
         return (True, tarball)
 
+
 def unpack_orig(archive, tmpdir, filters):
     """
     unpack a .orig.tar.gz to tmpdir, leave the cleanup to the caller in case of
@@ -255,6 +283,7 @@ def unpack_orig(archive, tmpdir, filters):
         raise GbpError
     return unpackArchive.dir
 
+
 def repack_orig(archive, tmpdir, dest):
     """
     recreate a new .orig.tar.gz from tmpdir (useful when using filter option)
@@ -267,6 +296,7 @@ def repack_orig(archive, tmpdir, dest):
         raise GbpError
     return repackArchive.dir
 
+
 def tar_toplevel(dir):
     """tar archives can contain a leading directory not"""
     unpacked = glob.glob('%s/*' % dir)
@@ -323,4 +353,10 @@ def guess_upstream_version(archive, version_regex=r''):
         if m:
             return m.group('version')
 
+
+def compare_versions(version1, version2):
+    """compares to Debian versionnumbers suitable for sort()"""
+    return DpkgCompareVersions()(version1, version2)
+
+
 # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
index ef0a028..bfece56 100755 (executable)
@@ -24,33 +24,10 @@ import re
 import sys
 import tempfile
 import gbp.command_wrappers as gbpc
-from gbp.deb import parse_dsc, DscFile
+from gbp.deb import parse_dsc, DscFile, DpkgCompareVersions
 from gbp.errors import GbpError
 from gbp.git import GitRepository, GitRepositoryError
 
-class DpkgCompareVersions(gbpc.Command):
-    cmd='/usr/bin/dpkg'
-
-    def __init__(self):
-        if not os.access(self.cmd, os.X_OK):
-            raise GbpError, "%s not found - cannot use compare versions" % self.cmd
-        gbpc.Command.__init__(self, self.cmd, ['--compare-versions'])
-
-    def __call__(self, version1, version2):
-        self.run_error = "Couldn't compare %s with %s" % (version1, version2)
-        res = gbpc.Command.call(self, [ version1, 'lt', version2 ])
-        if res not in [ 0, 1 ]:
-            raise gbpc.CommandExecFailed, "%s: bad return code %d" % (self.run_error, res)
-        if res == 0:
-            return -1
-        elif res == 1:
-            res = gbpc.Command.call(self, [ version1, 'gt', version2 ])
-            if res not in [ 0, 1 ]:
-                raise gbpc.CommandExecFailed, "%s: bad return code %d" % (self.run_error, res)
-            if res == 0:
-                return 1
-        return 0
-
 
 class DscCompareVersions(DpkgCompareVersions):
     def __init__(self):