fw at alioth.debian.org
2008-Dec-02 21:13 UTC
[Secure-testing-commits] r10579 - lib/python
Author: fw Date: 2008-12-02 21:13:06 +0000 (Tue, 02 Dec 2008) New Revision: 10579 Modified: lib/python/debian_support.py Log: 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. Modified: lib/python/debian_support.py ==================================================================--- lib/python/debian_support.py 2008-12-02 19:55:00 UTC (rev 10578) +++ lib/python/debian_support.py 2008-12-02 21:13:06 UTC (rev 10579) @@ -55,9 +55,15 @@ 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.""" t = type(version) @@ -67,6 +73,7 @@ assert t == types.StringType, `version` assert version <> "" self.__asString = version + self.__forCompare = _version_normalize_regexp.sub("", version) def __str__(self): return self.__asString @@ -75,11 +82,16 @@ 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) +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) -version_compare = apt_pkg.VersionCompare - class PackageFile: """A Debian package file.