diff --git a/deluge/common.py b/deluge/common.py index 9208a84b2..6c4267590 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -570,13 +570,15 @@ class VersionSplit(object): """ def __init__(self, ver): ver = ver.lower() - vs = ver.split("_") if "_" in ver else ver.split("-") + vs = ver.replace("_", "-").split("-") self.version = [int(x) for x in vs[0].split(".")] self.suffix = None + self.dev = False if len(vs) > 1: - for s in ("rc", "alpha", "beta", "dev"): - if s in vs[1][:len(s)]: - self.suffix = vs[1] + if vs[1].startswith(("rc", "alpha", "beta")): + self.suffix = vs[1] + if vs[-1] == 'dev': + self.dev = True def __cmp__(self, ver): """ @@ -587,19 +589,8 @@ class VersionSplit(object): """ - if self.version > ver.version or (self.suffix and self.suffix[:3] == "dev"): - return 1 - if self.version < ver.version: - return -1 - - if self.version == ver.version: - if self.suffix == ver.suffix: - return 0 - if self.suffix is None: - return 1 - if ver.suffix is None: - return -1 - if self.suffix < ver.suffix: - return -1 - if self.suffix > ver.suffix: - return 1 + # If there is no suffix we use z because we want final + # to appear after alpha, beta, and rc alphabetically. + v1 = [self.version, self.suffix or 'z', self.dev] + v2 = [ver.version, ver.suffix or 'z', ver.dev] + return cmp(v1, v2) diff --git a/tests/test_common.py b/tests/test_common.py index 54e4fc371..a7425db36 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -48,7 +48,11 @@ class CommonTestCase(unittest.TestCase): self.failUnless(VersionSplit("1.2.1") < VersionSplit("1.2.2")) self.failUnless(VersionSplit("1.1.9") < VersionSplit("1.2.2")) self.failUnless(VersionSplit("1.2.2") > VersionSplit("1.2.1")) - self.failIf(VersionSplit("1.2.2") == VersionSplit("1.2.2-dev")) + self.failUnless(VersionSplit("1.2.2") < VersionSplit("1.2.2-dev")) + self.failUnless(VersionSplit("1.2.2-dev") < VersionSplit("1.3.0-rc2")) + self.failUnless(VersionSplit("1.2.2") > VersionSplit("1.2.2-rc2")) + self.failUnless(VersionSplit("1.2.2-rc2-dev") > VersionSplit("1.2.2-rc2")) + self.failUnless(VersionSplit("1.2.2-rc3") > VersionSplit("1.2.2-rc2")) self.failUnless(VersionSplit("0.14.9") == VersionSplit("0.14.9")) self.failUnless(VersionSplit("0.14.9") > VersionSplit("0.14.5")) self.failUnless(VersionSplit("0.14.10") >= VersionSplit("0.14.9"))