summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFlorian Weimer <fw@deneb.enyo.de>2008-12-02 21:13:06 +0000
committerFlorian Weimer <fw@deneb.enyo.de>2008-12-02 21:13:06 +0000
commit5853b8a25c4c7b6b531fa04645e2bae40fbd7a40 (patch)
tree51ae15c4b66aad1d8be6165c779dce9c6faee330 /lib
parent32ec8bc734f40bc50bcb749575611356209d137f (diff)
lib/python/debian_support.py: Normalize version numbers before comparison
In theory, this allows us to use the data for unstable for volatile and backports.org. However, more testing is required if this is indeed effective, and volatile does not actually use the version number scheme assumed in this change. git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@10579 e39458fd-73e7-0310-bf30-c45bca0a0e42
Diffstat (limited to 'lib')
-rw-r--r--lib/python/debian_support.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/python/debian_support.py b/lib/python/debian_support.py
index 827a7a49fb..4c1f758888 100644
--- a/lib/python/debian_support.py
+++ b/lib/python/debian_support.py
@@ -55,8 +55,14 @@ class ParseError(Exception):
file.write("%s:%d: %s\n" % (self.filename, self.lineno, self.msg))
file.flush()
+# This regular expression is used to strip ~bpo1 and ~volatile1 from
+# version numbers before they are compared.
+_version_normalize_regexp = re.compile(r"~(?:bpo|volatile)[0-9.+]+$")
+
class Version:
- """Version class which uses the original APT comparison algorithm."""
+ """Version class which uses the original APT comparison algorithm.
+
+ ~bpo and ~volatile suffixes are ignored."""
def __init__(self, version):
"""Creates a new Version object."""
@@ -67,6 +73,7 @@ class Version:
assert t == types.StringType, `version`
assert version <> ""
self.__asString = version
+ self.__forCompare = _version_normalize_regexp.sub("", version)
def __str__(self):
return self.__asString
@@ -75,10 +82,15 @@ class Version:
return 'Version(%s)' % `self.__asString`
def __cmp__(self, other):
- return apt_pkg.VersionCompare(self.__asString, other.__asString)
+ return apt_pkg.VersionCompare(self.__forCompare, other.__forCompare)
-
-version_compare = apt_pkg.VersionCompare
+def version_compare(a, b, vc = apt_pkg.VersionCompare):
+ """Compares two versions according to the Debian algorithm.
+
+ ~bpo and ~volatile suffixes are ignored."""
+ a = _version_normalize_regexp.sub("", a)
+ b = _version_normalize_regexp.sub("", b)
+ return vc(a, b)
class PackageFile:
"""A Debian package file.

© 2014-2024 Faster IT GmbH | imprint | privacy policy