From 029cc95a161033c3791bd55e77bcba0c54e9b989 Mon Sep 17 00:00:00 2001 From: Kiooeht Date: Sun, 29 May 2011 11:02:10 -0700 Subject: [PATCH] Threaded update checker, allows PC to start up while checking for updates --- pesterchum.py | 16 +++++++++++++--- version.py | 16 +++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pesterchum.py b/pesterchum.py index 6f953a6..48c433e 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -2850,9 +2850,13 @@ class MainProgram(QtCore.QObject): self.connectWidgets(self.irc, self.widget) if self.widget.config.checkForUpdates(): - (new,url) = version.updateCheck() - if new: - self.widget.pcUpdate.emit(new, url) + import Queue + import threading + q = Queue.Queue(1) + s = threading.Thread(target=version.updateCheck, args=(q,0)) # the 0 is to stop + w = threading.Thread(target=self.showUpdate, args=(q,0)) # stupid syntax errors + w.start() + s.start() widget2irc = [('sendMessage(QString, QString)', 'sendMessage(QString, QString)'), @@ -2940,6 +2944,12 @@ class MainProgram(QtCore.QObject): self.disconnect(self.irc, QtCore.SIGNAL('finished()'), self, QtCore.SLOT('restartIRC()')) + def showUpdate(self, q,num): + new_url = q.get() + if new_url[0]: + self.widget.pcUpdate.emit(new_url[0], new_url[1]) + q.task_done() + def showLoading(self, widget, msg="CONN3CT1NG"): self.widget.show() if hasattr(self.widget, 'loadingscreen') and widget.loadingscreen: diff --git a/version.py b/version.py index f176bcc..1e2e5a3 100644 --- a/version.py +++ b/version.py @@ -1,5 +1,6 @@ import urllib import re +import time USER_TYPE = "dev" @@ -26,30 +27,31 @@ def verStrToNum(ver): full = ver[:ver.find(":")] return full,w.group(1),w.group(2),w.group(3),w.group(4),w.group(5) -def updateCheck(): +def updateCheck(q,num): + time.sleep(3) data = urllib.urlencode({"type" : USER_TYPE}) try: f = urllib.urlopen("http://distantsphere.com/pesterchum.php?" + data) except: - print "Update check Failure: 1"; return False,1 + print "Update check Failure: 1"; q.put((False,1)) newest = f.read() f.close() if not newest or newest[0] == "<": - print "Update check Failure: 2"; return False,2 + print "Update check Failure: 2"; q.put((False,2)) try: (full, major, minor, status, revision, url) = verStrToNum(newest) except TypeError: - return False,3 + return q.put((False,3)) print full if major <= _pcMajor: if minor <= _pcMinor: if status: if status <= _pcStatus: if revision <= _pcRevision: - return False,0 + return q.put((False,0)) else: if not _pcStatus: if revision <= _pcRevision: - return False,0 + return q.put((False,0)) print "A new version of Pesterchum is avaliable!" - return full,url + q.put((full,url))