summaryrefslogtreecommitdiffstats
path: root/deluge/common.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind@gmail.com>2018-04-25 20:10:52 +0100
committerCalum Lind <calumlind@gmail.com>2018-06-01 08:59:24 +0100
commit7cc9aaca49b8632382bed023f821bc5bedde9e20 (patch)
tree04a47b40475b5c83e3c45eadfd5cfe779bea9a37 /deluge/common.py
parent196aa48727276fafeb16bc7d845c91e55995652e (diff)
downloaddeluge-7cc9aaca49b8632382bed023f821bc5bedde9e20.tar.gz
deluge-7cc9aaca49b8632382bed023f821bc5bedde9e20.tar.bz2
deluge-7cc9aaca49b8632382bed023f821bc5bedde9e20.zip
Fix VersionSplit comparison
The tests on Python revealed a bug with comparing dev versions. Switch to comparing by integers and setting non-dev version to infinity. There is still an issue with suffix release comparisons beyond single digits but will leave that for now.
Diffstat (limited to 'deluge/common.py')
-rw-r--r--deluge/common.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/deluge/common.py b/deluge/common.py
index 64d76b685..aef5a3d3c 100644
--- a/deluge/common.py
+++ b/deluge/common.py
@@ -992,25 +992,27 @@ class VersionSplit(object):
self.version = [int(x) for x in vs[0].split('.') if x.isdigit()]
self.version_string = ''.join(str(x) for x in vs[0].split('.') if x.isdigit())
self.suffix = None
- self.dev = False
+ self.dev = None
if len(vs) > 1:
if vs[1].startswith(('rc', 'a', 'b', 'c')):
self.suffix = vs[1]
if vs[-1].startswith('dev'):
- self.dev = vs[-1]
+ try:
+ # Store only the dev numeral.
+ self.dev = int(vs[-1].rsplit('dev')[1])
+ except ValueError:
+ # Implicit dev numeral is 0.
+ self.dev = 0
def get_comparable_versions(self, other):
"""
Returns a 2-tuple of lists for use in the comparison
methods.
"""
- # PEP 386 versions with .devN precede release version
- if bool(self.dev) != bool(other.dev):
- if self.dev != 'dev':
- self.dev = not self.dev
- if other.dev != 'dev':
- other.dev = not other.dev
-
+ # PEP 386 versions with .devN precede release version so default
+ # non-dev versions to infinity while dev versions are ints.
+ self.dev = float('inf') if self.dev is None else self.dev
+ other.dev = float('inf') if other.dev is None else other.dev
# 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]