Cleaned up the update checker.
I also quieted it down in the logs. Rewrite pending. (Now that Homestuck is over, is there really any need for this?...)
This commit is contained in:
parent
5c9615cd4c
commit
b8c89856e0
1 changed files with 17 additions and 9 deletions
|
@ -1,15 +1,24 @@
|
||||||
# Adapted from Eco-Mono's F5Stuck RSS Client
|
# Adapted from Eco-Mono's F5Stuck RSS Client
|
||||||
|
|
||||||
|
# karxi: Now that Homestuck is over, this might be removed.
|
||||||
|
# Even if it isn't, it needs cleanup; the code is unpleasant.
|
||||||
|
|
||||||
from libs import feedparser
|
from libs import feedparser
|
||||||
import pickle
|
import pickle
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from time import mktime
|
from time import mktime
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
|
||||||
class MSPAChecker(QtGui.QWidget):
|
class MSPAChecker(QtGui.QWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QtCore.QObject.__init__(self, parent)
|
#~QtCore.QObject.__init__(self, parent)
|
||||||
|
# karxi: Why would you do that?
|
||||||
|
super(MSPAChecker, self).__init__(parent)
|
||||||
self.mainwindow = parent
|
self.mainwindow = parent
|
||||||
self.refreshRate = 30 # seconds
|
self.refreshRate = 30 # seconds
|
||||||
self.status = None
|
self.status = None
|
||||||
|
@ -21,9 +30,8 @@ class MSPAChecker(QtGui.QWidget):
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
try:
|
try:
|
||||||
current_status = open("status_new.pkl","w")
|
with open("status_new.pkl", "w") as current_status:
|
||||||
pickle.dump(self.status, current_status)
|
pickle.dump(self.status, current_status)
|
||||||
current_status.close()
|
|
||||||
try:
|
try:
|
||||||
os.rename("status.pkl","status_old.pkl")
|
os.rename("status.pkl","status_old.pkl")
|
||||||
except:
|
except:
|
||||||
|
@ -37,7 +45,7 @@ class MSPAChecker(QtGui.QWidget):
|
||||||
if os.path.exists("status_old.pkl"):
|
if os.path.exists("status_old.pkl"):
|
||||||
os.remove("status_old.pkl")
|
os.remove("status_old.pkl")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e
|
logging.error("Error: %s", e, exc_info=sys.exc_info())
|
||||||
msg = QtGui.QMessageBox(self)
|
msg = QtGui.QMessageBox(self)
|
||||||
msg.setText("Problems writing save file.")
|
msg.setText("Problems writing save file.")
|
||||||
msg.show()
|
msg.show()
|
||||||
|
@ -48,7 +56,7 @@ class MSPAChecker(QtGui.QWidget):
|
||||||
return
|
return
|
||||||
if self.lock:
|
if self.lock:
|
||||||
return
|
return
|
||||||
print "Checking MSPA updates..."
|
logging.debug("Checking MSPA updates...")
|
||||||
s = threading.Thread(target=self.check_site)
|
s = threading.Thread(target=self.check_site)
|
||||||
s.start()
|
s.start()
|
||||||
|
|
||||||
|
@ -85,14 +93,14 @@ class MSPAChecker(QtGui.QWidget):
|
||||||
self, QtCore.SLOT('nothing()'))
|
self, QtCore.SLOT('nothing()'))
|
||||||
self.mspa.show()
|
self.mspa.show()
|
||||||
else:
|
else:
|
||||||
#print "No new updates :("
|
#logging.info("No new updates :(")
|
||||||
pass
|
pass
|
||||||
if must_save:
|
if must_save:
|
||||||
self.save_state()
|
self.save_state()
|
||||||
|
|
||||||
@QtCore.pyqtSlot()
|
@QtCore.pyqtSlot()
|
||||||
def visit_site(self):
|
def visit_site(self):
|
||||||
print self.status['last_visited']['link']
|
logging.debug(self.status['last_visited']['link'])
|
||||||
QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.status['last_visited']['link'], QtCore.QUrl.TolerantMode))
|
QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.status['last_visited']['link'], QtCore.QUrl.TolerantMode))
|
||||||
if self.status['last_seen']['pubdate'] > self.status['last_visited']['pubdate']:
|
if self.status['last_seen']['pubdate'] > self.status['last_visited']['pubdate']:
|
||||||
#Visited for the first time. Untrip the icon and remember that we saw it.
|
#Visited for the first time. Untrip the icon and remember that we saw it.
|
||||||
|
@ -105,7 +113,7 @@ class MSPAChecker(QtGui.QWidget):
|
||||||
|
|
||||||
class MSPAUpdateWindow(QtGui.QDialog):
|
class MSPAUpdateWindow(QtGui.QDialog):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QtGui.QDialog.__init__(self, parent)
|
super(MSPAUpdateWindow, self).__init__(parent)
|
||||||
self.mainwindow = parent
|
self.mainwindow = parent
|
||||||
self.setStyleSheet(self.mainwindow.theme["main/defaultwindow/style"])
|
self.setStyleSheet(self.mainwindow.theme["main/defaultwindow/style"])
|
||||||
self.setWindowTitle("MSPA Update!")
|
self.setWindowTitle("MSPA Update!")
|
||||||
|
|
Loading…
Reference in a new issue