mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-17 05:47:50 +00:00
Fix VersionSplit comparison to do a proper compare and not simply
against the version strings
This commit is contained in:
parent
6aacc6e75c
commit
9d13b17a3c
@ -210,7 +210,7 @@ def open_url_in_browser(url):
|
|||||||
|
|
||||||
:param url: the url to open
|
:param url: the url to open
|
||||||
:type url: string
|
:type url: string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import webbrowser
|
import webbrowser
|
||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
@ -468,13 +468,13 @@ def free_space(path):
|
|||||||
:type path: string
|
:type path: string
|
||||||
:returns: the free space at path in bytes
|
:returns: the free space at path in bytes
|
||||||
:rtype: int
|
:rtype: int
|
||||||
|
|
||||||
:raises InvalidPathError: if the path is not valid
|
:raises InvalidPathError: if the path is not valid
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise InvalidPathError("%s is not a valid path" % path)
|
raise InvalidPathError("%s is not a valid path" % path)
|
||||||
|
|
||||||
if windows_check():
|
if windows_check():
|
||||||
import win32file
|
import win32file
|
||||||
sectors, bytes, free, total = map(long, win32file.GetDiskFreeSpace(path))
|
sectors, bytes, free, total = map(long, win32file.GetDiskFreeSpace(path))
|
||||||
@ -513,19 +513,19 @@ def is_ip(ip):
|
|||||||
return True
|
return True
|
||||||
except socket.error:
|
except socket.error:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class VersionSplit(object):
|
class VersionSplit(object):
|
||||||
"""
|
"""
|
||||||
Used for comparing version numbers.
|
Used for comparing version numbers.
|
||||||
|
|
||||||
:param ver: the version
|
:param ver: the version
|
||||||
:type ver: string
|
:type ver: string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, ver):
|
def __init__(self, ver):
|
||||||
ver = ver.lower()
|
ver = ver.lower()
|
||||||
vs = ver.split("_") if "_" in ver else ver.split("-")
|
vs = ver.split("_") if "_" in ver else ver.split("-")
|
||||||
self.version = vs[0]
|
self.version = [int(x) for x in vs[0].split(".")]
|
||||||
self.suffix = None
|
self.suffix = None
|
||||||
if len(vs) > 1:
|
if len(vs) > 1:
|
||||||
for s in ("rc", "alpha", "beta", "dev"):
|
for s in ("rc", "alpha", "beta", "dev"):
|
||||||
@ -535,12 +535,12 @@ class VersionSplit(object):
|
|||||||
def __cmp__(self, ver):
|
def __cmp__(self, ver):
|
||||||
"""
|
"""
|
||||||
The comparison method.
|
The comparison method.
|
||||||
|
|
||||||
:param ver: the version to compare with
|
:param ver: the version to compare with
|
||||||
:type ver: VersionSplit
|
:type ver: VersionSplit
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.version > ver.version or (self.suffix and self.suffix[:3] == "dev"):
|
if self.version > ver.version or (self.suffix and self.suffix[:3] == "dev"):
|
||||||
return 1
|
return 1
|
||||||
if self.version < ver.version:
|
if self.version < ver.version:
|
||||||
|
11
tests/test_versionsplit.py
Normal file
11
tests/test_versionsplit.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from twisted.trial import unittest
|
||||||
|
from deluge.common import VersionSplit
|
||||||
|
|
||||||
|
class VersionSplitTestClass(unittest.TestCase):
|
||||||
|
def test_compare(self):
|
||||||
|
vs1 = VersionSplit("0.14.9")
|
||||||
|
vs2 = VersionSplit("0.14.10")
|
||||||
|
vs3 = VersionSplit("0.14.5")
|
||||||
|
|
||||||
|
self.assertTrue(vs1 > vs3)
|
||||||
|
self.assertTrue(vs2 > vs1)
|
Loading…
x
Reference in New Issue
Block a user