diff options
author | Guido Günther <agx@sigxcpu.org> | 2010-08-12 22:05:40 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2010-08-12 22:06:08 +0200 |
commit | 5e3c9d09b0e757f4ae68f82e9c2586c97a6ffbe9 (patch) | |
tree | 2175c3fb7e71b7436df4ec665c17f73ea31bac75 | |
parent | 4d4313d371e79a632a178ec5a6a2b4108b5243ba (diff) | |
download | git-buildpackage-5e3c9d09b0e757f4ae68f82e9c2586c97a6ffbe9.tar.gz git-buildpackage-5e3c9d09b0e757f4ae68f82e9c2586c97a6ffbe9.tar.bz2 git-buildpackage-5e3c9d09b0e757f4ae68f82e9c2586c97a6ffbe9.zip |
Move DpkgCompareVersions and add compare_versions
Git-Dch: Ignore
-rw-r--r-- | gbp/deb.py | 36 | ||||
-rwxr-xr-x | git-import-dscs | 25 |
2 files changed, 37 insertions, 24 deletions
@@ -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\:·: diff --git a/git-import-dscs b/git-import-dscs index ef0a0283..bfece560 100755 --- a/git-import-dscs +++ b/git-import-dscs @@ -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): |