1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>
Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import data
import threading
import urllib2
import sys
import traceback
class VersionChecker(threading.Thread):
def __init__(self, settings, verbose=False):
self.settings = settings
self.verbose = verbose
super(VersionChecker, self).__init__()
def _set_daemon(self):
return True # Don't block application exit
def run(self):
from taskcoachlib.gui.dialog import version
try:
latestVersionString = self.getLatestVersion()
latestVersion = self.tupleVersion(latestVersionString)
lastVersionNotified = self.tupleVersion(self.getLastVersionNotified())
currentVersion = self.tupleVersion(data.version)
except:
if self.verbose:
self.notifyUser(version.NoVersionDialog,
message=''.join(traceback.format_exception_only(sys.exc_type, sys.exc_value)))
else:
if latestVersion < currentVersion and self.verbose:
self.notifyUser(version.PrereleaseVersionDialog, latestVersionString)
elif latestVersion == currentVersion and self.verbose:
self.notifyUser(version.VersionUpToDateDialog, latestVersionString)
elif latestVersion > currentVersion and (self.verbose or latestVersion > lastVersionNotified):
self.setLastVersionNotified(latestVersionString)
self.notifyUser(version.NewVersionDialog, latestVersionString)
def getLatestVersion(self):
versionText = self.parseVersionFile(self.retrieveVersionFile())
return versionText.strip()
def notifyUser(self, dialog, latestVersion='', message=''):
# Must use CallAfter because this is a non-GUI thread
# Import wx here so it isn't a build dependency
import wx
wx.CallAfter(self.showDialog, dialog, latestVersion, message)
def showDialog(self, VersionDialog, latestVersion, message=''):
import wx
dialog = VersionDialog(wx.GetApp().GetTopWindow(),
version=latestVersion, message=message,
settings=self.settings)
dialog.Show()
return dialog
def getLastVersionNotified(self):
return self.settings.get('version', 'notified')
def setLastVersionNotified(self, lastVersionNotifiedString):
self.settings.set('version', 'notified', lastVersionNotifiedString)
@staticmethod
def parseVersionFile(versionFile):
return versionFile.readline()
@staticmethod
def retrieveVersionFile():
return urllib2.urlopen(data.version_url)
@staticmethod
def tupleVersion(versionString):
return tuple(int(i) for i in versionString.split('.'))
|