Module: deluge
Branch: 1.2-stable
Commit: 90103358f3713c343c017d3eb15867a1f52bb0ed

Author: Andrew Resch <[email protected]>
Date:   Sun Mar 21 15:57:53 2010 -0700

Fix VersionSplit comparison to do a proper compare and not simply
against the version strings

---

 deluge/common.py           |   20 ++++++++++----------
 tests/test_versionsplit.py |   11 +++++++++++
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/deluge/common.py b/deluge/common.py
index cae8222..d82466d 100644
--- a/deluge/common.py
+++ b/deluge/common.py
@@ -210,7 +210,7 @@ def open_url_in_browser(url):
 
     :param url: the url to open
     :type url: string
-    
+
     """
     import webbrowser
     webbrowser.open(url)
@@ -469,13 +469,13 @@ def free_space(path):
     :type path: string
     :returns: the free space at path in bytes
     :rtype: int
-    
+
     :raises InvalidPathError: if the path is not valid
 
     """
     if not os.path.exists(path):
         raise InvalidPathError("%s is not a valid path" % path)
-        
+
     if windows_check():
         import win32file
         sectors, bytes, free, total = map(long, 
win32file.GetDiskFreeSpace(path))
@@ -514,19 +514,19 @@ 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.version = [int(x) for x in vs[0].split(".")]
         self.suffix = None
         if len(vs) > 1:
             for s in ("rc", "alpha", "beta", "dev"):
@@ -536,12 +536,12 @@ class VersionSplit(object):
     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:
diff --git a/tests/test_versionsplit.py b/tests/test_versionsplit.py
new file mode 100644
index 0000000..77ef1df
--- /dev/null
+++ b/tests/test_versionsplit.py
@@ -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)

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to