mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
fix regexp and compare_versions
This commit is contained in:
parent
c933e6c614
commit
e0bdf0e079
1 changed files with 16 additions and 7 deletions
|
@ -75,21 +75,30 @@ class UpdateLabel(QtGui.QLabel):
|
||||||
if res.status == 200:
|
if res.status == 200:
|
||||||
self.latest_version = res.read()
|
self.latest_version = res.read()
|
||||||
self.latest_version = self.latest_version.replace("\n","")
|
self.latest_version = self.latest_version.replace("\n","")
|
||||||
if(re.match('^\d\.\d.\d$', self.latest_version)):
|
if(re.match('^\d+(\.\d+)*$', self.latest_version)):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
self.current_version = ELECTRUM_VERSION
|
self.current_version = ELECTRUM_VERSION
|
||||||
|
|
||||||
if(self.compare_versions(self.latest_version, self.current_version) == 1):
|
if(self.compare_versions(self.latest_version, self.current_version) == 1):
|
||||||
latest_seen = self.config.get("last_seen_version")
|
latest_seen = self.config.get("last_seen_version",ELECTRUM_VERSION)
|
||||||
if(self.compare_versions(self.latest_version, latest_seen) == 1):
|
if(self.compare_versions(self.latest_version, latest_seen) == 1):
|
||||||
self.setText(_("New version available") + ": " + self.latest_version)
|
self.setText(_("New version available") + ": " + self.latest_version)
|
||||||
|
|
||||||
|
|
||||||
def compare_versions(self, version1, version2):
|
def compare_versions(self, version1, version2):
|
||||||
def normalize(v):
|
parts1 = [int(x) for x in version1.split('.')]
|
||||||
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
|
parts2 = [int(x) for x in version2.split('.')]
|
||||||
return cmp(normalize(version1), normalize(version2))
|
|
||||||
|
# fill up the shorter version with zeros ...
|
||||||
|
lendiff = len(parts1) - len(parts2)
|
||||||
|
if lendiff > 0:
|
||||||
|
parts2.extend([0] * lendiff)
|
||||||
|
elif lendiff < 0:
|
||||||
|
parts1.extend([0] * (-lendiff))
|
||||||
|
|
||||||
|
for i, p in enumerate(parts1):
|
||||||
|
ret = cmp(p, parts2[i])
|
||||||
|
if ret: return ret
|
||||||
|
return 0
|
||||||
|
|
||||||
def ignore_this_version(self):
|
def ignore_this_version(self):
|
||||||
self.setText("")
|
self.setText("")
|
||||||
|
|
Loading…
Add table
Reference in a new issue