Threaded update checker, allows PC to start up while checking for updates
This commit is contained in:
parent
e364f6e4cd
commit
029cc95a16
2 changed files with 22 additions and 10 deletions
|
@ -2850,9 +2850,13 @@ class MainProgram(QtCore.QObject):
|
||||||
self.connectWidgets(self.irc, self.widget)
|
self.connectWidgets(self.irc, self.widget)
|
||||||
|
|
||||||
if self.widget.config.checkForUpdates():
|
if self.widget.config.checkForUpdates():
|
||||||
(new,url) = version.updateCheck()
|
import Queue
|
||||||
if new:
|
import threading
|
||||||
self.widget.pcUpdate.emit(new, url)
|
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)',
|
widget2irc = [('sendMessage(QString, QString)',
|
||||||
'sendMessage(QString, QString)'),
|
'sendMessage(QString, QString)'),
|
||||||
|
@ -2940,6 +2944,12 @@ class MainProgram(QtCore.QObject):
|
||||||
self.disconnect(self.irc, QtCore.SIGNAL('finished()'),
|
self.disconnect(self.irc, QtCore.SIGNAL('finished()'),
|
||||||
self, QtCore.SLOT('restartIRC()'))
|
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"):
|
def showLoading(self, widget, msg="CONN3CT1NG"):
|
||||||
self.widget.show()
|
self.widget.show()
|
||||||
if hasattr(self.widget, 'loadingscreen') and widget.loadingscreen:
|
if hasattr(self.widget, 'loadingscreen') and widget.loadingscreen:
|
||||||
|
|
16
version.py
16
version.py
|
@ -1,5 +1,6 @@
|
||||||
import urllib
|
import urllib
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
USER_TYPE = "dev"
|
USER_TYPE = "dev"
|
||||||
|
|
||||||
|
@ -26,30 +27,31 @@ def verStrToNum(ver):
|
||||||
full = ver[:ver.find(":")]
|
full = ver[:ver.find(":")]
|
||||||
return full,w.group(1),w.group(2),w.group(3),w.group(4),w.group(5)
|
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})
|
data = urllib.urlencode({"type" : USER_TYPE})
|
||||||
try:
|
try:
|
||||||
f = urllib.urlopen("http://distantsphere.com/pesterchum.php?" + data)
|
f = urllib.urlopen("http://distantsphere.com/pesterchum.php?" + data)
|
||||||
except:
|
except:
|
||||||
print "Update check Failure: 1"; return False,1
|
print "Update check Failure: 1"; q.put((False,1))
|
||||||
newest = f.read()
|
newest = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
if not newest or newest[0] == "<":
|
if not newest or newest[0] == "<":
|
||||||
print "Update check Failure: 2"; return False,2
|
print "Update check Failure: 2"; q.put((False,2))
|
||||||
try:
|
try:
|
||||||
(full, major, minor, status, revision, url) = verStrToNum(newest)
|
(full, major, minor, status, revision, url) = verStrToNum(newest)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return False,3
|
return q.put((False,3))
|
||||||
print full
|
print full
|
||||||
if major <= _pcMajor:
|
if major <= _pcMajor:
|
||||||
if minor <= _pcMinor:
|
if minor <= _pcMinor:
|
||||||
if status:
|
if status:
|
||||||
if status <= _pcStatus:
|
if status <= _pcStatus:
|
||||||
if revision <= _pcRevision:
|
if revision <= _pcRevision:
|
||||||
return False,0
|
return q.put((False,0))
|
||||||
else:
|
else:
|
||||||
if not _pcStatus:
|
if not _pcStatus:
|
||||||
if revision <= _pcRevision:
|
if revision <= _pcRevision:
|
||||||
return False,0
|
return q.put((False,0))
|
||||||
print "A new version of Pesterchum is avaliable!"
|
print "A new version of Pesterchum is avaliable!"
|
||||||
return full,url
|
q.put((full,url))
|
||||||
|
|
Loading…
Reference in a new issue