From d685b2ddd6fe1f4775575a523a098d82347e8044 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Thu, 30 Jul 2009 21:14:50 +0000 Subject: [PATCH] Move the VersionSplit class to deluge.common --- deluge/common.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ deluge/core/core.py | 31 +------------------------------ 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/deluge/common.py b/deluge/common.py index b8992b21e..8e15ceca6 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -505,3 +505,47 @@ def is_ip(ip): return True except socket.error: return False + +class VersionSplit(object): + """ + Used for comparing version numbers. + + :param ver: the version + :type ver: string + + """ + def __init__(self, ver): + ver = ver.lower() + vs = ver.split("_") if "_" in ver else ver.split("-") + self.version = vs[0] + self.suffix = None + if len(vs) > 1: + for s in ("rc", "alpha", "beta", "dev"): + if s in vs[1][:len(s)]: + self.suffix = vs[1] + + def __cmp__(self, ver): + """ + The comparison method. + + :param ver: the version to compare with + :type ver: VersionSplit + + """ + + 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 diff --git a/deluge/core/core.py b/deluge/core/core.py index 60175eee6..1c1bfd607 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -183,36 +183,7 @@ class Core(component.Component): def check_new_release(self): if self.new_release: log.debug("new_release: %s", self.new_release) - class VersionSplit(object): - def __init__(self, ver): - ver = ver.lower() - vs = ver.split("_") if "_" in ver else ver.split("-") - self.version = vs[0] - self.suffix = None - if len(vs) > 1: - for s in ("rc", "alpha", "beta", "dev"): - if s in vs[1][:len(s)]: - self.suffix = vs[1] - - def __cmp__(self, ver): - 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 VersionSplit(self.new_release) > VersionSplit(deluge.common.get_version()): + if deluge.common.VersionSplit(self.new_release) > deluge.common.VersionSplit(deluge.common.get_version()): component.get("EventManager").emit(NewVersionAvailableEvent(self.new_release)) return self.new_release return False