From 5dfc22d66d8fa7234eb10ee8093def4ad17295f4 Mon Sep 17 00:00:00 2001 From: ruppert Date: Fri, 21 Sep 2012 19:33:14 +0000 Subject: [PATCH] ENH: updater added --- invesalius/constants.py | 1 + invesalius/control.py | 3 --- invesalius/invesalius.py | 7 +++++++ invesalius/project.py | 2 +- invesalius/session.py | 29 ++++++++++++++++++++++++++++- invesalius/utils.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 5 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index 06cf402..93eaff7 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -24,6 +24,7 @@ import wx from project import Project +INVESALIUS_VERSION = "3.0 beta 3" #--------------- diff --git a/invesalius/control.py b/invesalius/control.py index 630a8f8..3588300 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -59,9 +59,6 @@ class Controller(): Publisher.sendMessage('Load Preferences') - # Check for updates - #subprocess.Popen([sys.executable, 'update.py' ,ses.Session().language]) - def __bind_events(self): Publisher.subscribe(self.OnImportMedicalImages, 'Import directory') Publisher.subscribe(self.OnShowDialogImportDirectory, diff --git a/invesalius/invesalius.py b/invesalius/invesalius.py index 6029941..c7084f1 100755 --- a/invesalius/invesalius.py +++ b/invesalius/invesalius.py @@ -55,6 +55,7 @@ import utils # ------------------------------------------------------------------ + class InVesalius(wx.App): """ InVesalius wxPython application class. @@ -299,6 +300,12 @@ if __name__ == '__main__': # import modules as they were on root invesalius folder sys.path.append(".") + # Check for updates + from multiprocessing import Process + p = Process(target=utils.UpdateCheck, args=()) + p.daemon=True + p.start() + # Init application main() diff --git a/invesalius/project.py b/invesalius/project.py index ad51510..bde0ee9 100755 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -210,7 +210,7 @@ class Project(object): project = { # Format info "format_version": 1, - "invesalius_version": "invesalius3b3", + "invesalius_version": const.INVESALIUS_VERSION, "date": datetime.datetime.now().isoformat(), # case info diff --git a/invesalius/session.py b/invesalius/session.py index 688ae35..b7cb8ae 100644 --- a/invesalius/session.py +++ b/invesalius/session.py @@ -28,6 +28,7 @@ import time from wx.lib.pubsub import pub as Publisher from utils import Singleton, debug +from random import randint class Session(object): # Only one session will be initialized per time. Therefore, we use @@ -63,6 +64,9 @@ class Session(object): # GUI language self.language = "" # "pt_BR", "es" + self.random_id = randint(0,pow(10,16)) + print self.random_id + # Recent projects list self.recent_projects = [(const.SAMPLE_DIR, "Cranium.inv3")] self.last_dicom_folder = '' @@ -151,6 +155,7 @@ class Session(object): config.set('session', 'status', self.project_status) config.set('session','debug', self.debug) config.set('session', 'language', self.language) + config.set('session', 'random_id', self.random_id) config.set('session', 'surface_interpolation', self.surface_interpolation) config.set('session', 'rendering', self.rendering) @@ -194,6 +199,12 @@ class Session(object): def SetLanguage(self, language): self.language = language + def GetRandomId(self): + return self.random_id + + def SetRandomId(self, random_id): + self.random_id = random_id + def GetLastDicomFolder(self): return self.last_dicom_folder @@ -214,6 +225,19 @@ class Session(object): ConfigParser.MissingSectionHeaderError): return False + def ReadRandomId(self): + config = ConfigParser.ConfigParser() + home_path = os.path.expanduser('~') + path = os.path.join(home_path ,'.invesalius', 'config.cfg') + try: + config.read(path) + self.random_id = config.get('session','random_id') + return self.random_id + except (ConfigParser.NoSectionError, + ConfigParser.NoOptionError, + ConfigParser.MissingSectionHeaderError): + return False + def ReadSession(self): config = ConfigParser.ConfigParser() home_path = os.path.expanduser('~') @@ -224,6 +248,7 @@ class Session(object): self.project_status = config.get('session', 'status') self.debug = config.get('session','debug') self.language = config.get('session','language') + self.random_id = config.get('session','random_id') self.recent_projects = eval(config.get('project','recent_projects')) self.homedir = config.get('paths','homedir') @@ -248,7 +273,8 @@ class Session(object): #Added to fix new version compatibility self.surface_interpolation = 0 self.rendering = 0 - + self.random_id = randint(0,pow(10,16)) + self.CreateSessionFile() return True @@ -281,6 +307,7 @@ class WriteSession(Thread): config.set('session', 'status', self.session.project_status) config.set('session','debug', self.session.debug) config.set('session', 'language', self.session.language) + config.set('session', 'random_id', self.session.random_id) config.set('session', 'surface_interpolation', self.session.surface_interpolation) config.set('session', 'rendering', self.session.rendering) diff --git a/invesalius/utils.py b/invesalius/utils.py index 65ec6ee..51faea8 100755 --- a/invesalius/utils.py +++ b/invesalius/utils.py @@ -366,4 +366,55 @@ def get_system_encoding(): +def UpdateCheck(): + import urllib + import urllib2 + print "Checking updates..." + + # Check if there is a language set + import i18n + import session as ses + session = ses.Session() + install_lang = 0 + if session.ReadLanguage(): + lang = session.GetLanguage() + if (lang != "False"): + _ = i18n.InstallLanguage(lang) + install_lang = 1 + if (install_lang==0): + return + if session.ReadRandomId(): + random_id = session.GetRandomId() + + # Fetch update data from server + import constants as const + url = "http://www.cti.gov.br/dt3d/invesalius/update/checkupdate.php" + headers = { 'User-Agent' : 'Mozilla/5.0 (compatible; MSIE 5.5; Windows NT)' } + data = {'update_protocol_version' : '1', + 'invesalius_version' : const.INVESALIUS_VERSION, + 'platform' : sys.platform, + 'architecture' : platform.architecture()[0], + 'language' : lang, + 'random_id' : random_id } + data = urllib.urlencode(data) + req = urllib2.Request(url, data, headers) + response = urllib2.urlopen(req) + last = response.readline().rstrip() + url = response.readline().rstrip() + if (last!=const.INVESALIUS_VERSION+"1"): + print " ...New update found!!! -> version:", last #, ", url=",url + from time import sleep + sleep(2) + import wx + app=wx.App() + import i18n + _ = i18n.InstallLanguage(lang) + msg=_("A new version of InVesalius is available. Do you want to open the download website now?") + title=_("Invesalius Update") + msgdlg = wx.MessageDialog(None,msg,title, wx.YES_NO | wx.ICON_INFORMATION) + if (msgdlg.ShowModal()==wx.ID_YES): + wx.LaunchDefaultBrowser(url) + msgdlg.Destroy() + app.MainLoop() + -- libgit2 0.21.2