Skip to content

Commit

Permalink
Move DpkgCompareVersions and add compare_versions
Browse files Browse the repository at this point in the history
Git-Dch: Ignore
  • Loading branch information
agx committed Aug 12, 2010
1 parent 4d4313d commit 5e3c9d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
36 changes: 36 additions & 0 deletions gbp/deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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\:·:
25 changes: 1 addition & 24 deletions git-import-dscs
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5e3c9d0

Please sign in to comment.