From e0bdf0e079ec732b0c3764c2d70159c00f47d5bd Mon Sep 17 00:00:00 2001 From: thomasv Date: Wed, 16 Jan 2013 13:44:18 +0100 Subject: [PATCH] fix regexp and compare_versions --- lib/gui_qt.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/gui_qt.py b/lib/gui_qt.py index 3d91e437f..be19aab8c 100644 --- a/lib/gui_qt.py +++ b/lib/gui_qt.py @@ -75,21 +75,30 @@ class UpdateLabel(QtGui.QLabel): if res.status == 200: self.latest_version = res.read() 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.current_version = ELECTRUM_VERSION - 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): self.setText(_("New version available") + ": " + self.latest_version) def compare_versions(self, version1, version2): - def normalize(v): - return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")] - return cmp(normalize(version1), normalize(version2)) + parts1 = [int(x) for x in version1.split('.')] + parts2 = [int(x) for x in version2.split('.')] + + # 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): self.setText("")