Commit 5dfc22d66d8fa7234eb10ee8093def4ad17295f4
1 parent
d6cdcade
Exists in
master
and in
65 other branches
ENH: updater added
Showing
6 changed files
with
88 additions
and
5 deletions
Show diff stats
invesalius/constants.py
invesalius/control.py
| @@ -59,9 +59,6 @@ class Controller(): | @@ -59,9 +59,6 @@ class Controller(): | ||
| 59 | 59 | ||
| 60 | Publisher.sendMessage('Load Preferences') | 60 | Publisher.sendMessage('Load Preferences') |
| 61 | 61 | ||
| 62 | - # Check for updates | ||
| 63 | - #subprocess.Popen([sys.executable, 'update.py' ,ses.Session().language]) | ||
| 64 | - | ||
| 65 | def __bind_events(self): | 62 | def __bind_events(self): |
| 66 | Publisher.subscribe(self.OnImportMedicalImages, 'Import directory') | 63 | Publisher.subscribe(self.OnImportMedicalImages, 'Import directory') |
| 67 | Publisher.subscribe(self.OnShowDialogImportDirectory, | 64 | Publisher.subscribe(self.OnShowDialogImportDirectory, |
invesalius/invesalius.py
| @@ -55,6 +55,7 @@ import utils | @@ -55,6 +55,7 @@ import utils | ||
| 55 | 55 | ||
| 56 | # ------------------------------------------------------------------ | 56 | # ------------------------------------------------------------------ |
| 57 | 57 | ||
| 58 | + | ||
| 58 | class InVesalius(wx.App): | 59 | class InVesalius(wx.App): |
| 59 | """ | 60 | """ |
| 60 | InVesalius wxPython application class. | 61 | InVesalius wxPython application class. |
| @@ -299,6 +300,12 @@ if __name__ == '__main__': | @@ -299,6 +300,12 @@ if __name__ == '__main__': | ||
| 299 | # import modules as they were on root invesalius folder | 300 | # import modules as they were on root invesalius folder |
| 300 | sys.path.append(".") | 301 | sys.path.append(".") |
| 301 | 302 | ||
| 303 | + # Check for updates | ||
| 304 | + from multiprocessing import Process | ||
| 305 | + p = Process(target=utils.UpdateCheck, args=()) | ||
| 306 | + p.daemon=True | ||
| 307 | + p.start() | ||
| 308 | + | ||
| 302 | # Init application | 309 | # Init application |
| 303 | main() | 310 | main() |
| 304 | 311 |
invesalius/project.py
| @@ -210,7 +210,7 @@ class Project(object): | @@ -210,7 +210,7 @@ class Project(object): | ||
| 210 | project = { | 210 | project = { |
| 211 | # Format info | 211 | # Format info |
| 212 | "format_version": 1, | 212 | "format_version": 1, |
| 213 | - "invesalius_version": "invesalius3b3", | 213 | + "invesalius_version": const.INVESALIUS_VERSION, |
| 214 | "date": datetime.datetime.now().isoformat(), | 214 | "date": datetime.datetime.now().isoformat(), |
| 215 | 215 | ||
| 216 | # case info | 216 | # case info |
invesalius/session.py
| @@ -28,6 +28,7 @@ import time | @@ -28,6 +28,7 @@ import time | ||
| 28 | from wx.lib.pubsub import pub as Publisher | 28 | from wx.lib.pubsub import pub as Publisher |
| 29 | 29 | ||
| 30 | from utils import Singleton, debug | 30 | from utils import Singleton, debug |
| 31 | +from random import randint | ||
| 31 | 32 | ||
| 32 | class Session(object): | 33 | class Session(object): |
| 33 | # Only one session will be initialized per time. Therefore, we use | 34 | # Only one session will be initialized per time. Therefore, we use |
| @@ -63,6 +64,9 @@ class Session(object): | @@ -63,6 +64,9 @@ class Session(object): | ||
| 63 | # GUI language | 64 | # GUI language |
| 64 | self.language = "" # "pt_BR", "es" | 65 | self.language = "" # "pt_BR", "es" |
| 65 | 66 | ||
| 67 | + self.random_id = randint(0,pow(10,16)) | ||
| 68 | + print self.random_id | ||
| 69 | + | ||
| 66 | # Recent projects list | 70 | # Recent projects list |
| 67 | self.recent_projects = [(const.SAMPLE_DIR, "Cranium.inv3")] | 71 | self.recent_projects = [(const.SAMPLE_DIR, "Cranium.inv3")] |
| 68 | self.last_dicom_folder = '' | 72 | self.last_dicom_folder = '' |
| @@ -151,6 +155,7 @@ class Session(object): | @@ -151,6 +155,7 @@ class Session(object): | ||
| 151 | config.set('session', 'status', self.project_status) | 155 | config.set('session', 'status', self.project_status) |
| 152 | config.set('session','debug', self.debug) | 156 | config.set('session','debug', self.debug) |
| 153 | config.set('session', 'language', self.language) | 157 | config.set('session', 'language', self.language) |
| 158 | + config.set('session', 'random_id', self.random_id) | ||
| 154 | config.set('session', 'surface_interpolation', self.surface_interpolation) | 159 | config.set('session', 'surface_interpolation', self.surface_interpolation) |
| 155 | config.set('session', 'rendering', self.rendering) | 160 | config.set('session', 'rendering', self.rendering) |
| 156 | 161 | ||
| @@ -194,6 +199,12 @@ class Session(object): | @@ -194,6 +199,12 @@ class Session(object): | ||
| 194 | def SetLanguage(self, language): | 199 | def SetLanguage(self, language): |
| 195 | self.language = language | 200 | self.language = language |
| 196 | 201 | ||
| 202 | + def GetRandomId(self): | ||
| 203 | + return self.random_id | ||
| 204 | + | ||
| 205 | + def SetRandomId(self, random_id): | ||
| 206 | + self.random_id = random_id | ||
| 207 | + | ||
| 197 | def GetLastDicomFolder(self): | 208 | def GetLastDicomFolder(self): |
| 198 | return self.last_dicom_folder | 209 | return self.last_dicom_folder |
| 199 | 210 | ||
| @@ -214,6 +225,19 @@ class Session(object): | @@ -214,6 +225,19 @@ class Session(object): | ||
| 214 | ConfigParser.MissingSectionHeaderError): | 225 | ConfigParser.MissingSectionHeaderError): |
| 215 | return False | 226 | return False |
| 216 | 227 | ||
| 228 | + def ReadRandomId(self): | ||
| 229 | + config = ConfigParser.ConfigParser() | ||
| 230 | + home_path = os.path.expanduser('~') | ||
| 231 | + path = os.path.join(home_path ,'.invesalius', 'config.cfg') | ||
| 232 | + try: | ||
| 233 | + config.read(path) | ||
| 234 | + self.random_id = config.get('session','random_id') | ||
| 235 | + return self.random_id | ||
| 236 | + except (ConfigParser.NoSectionError, | ||
| 237 | + ConfigParser.NoOptionError, | ||
| 238 | + ConfigParser.MissingSectionHeaderError): | ||
| 239 | + return False | ||
| 240 | + | ||
| 217 | def ReadSession(self): | 241 | def ReadSession(self): |
| 218 | config = ConfigParser.ConfigParser() | 242 | config = ConfigParser.ConfigParser() |
| 219 | home_path = os.path.expanduser('~') | 243 | home_path = os.path.expanduser('~') |
| @@ -224,6 +248,7 @@ class Session(object): | @@ -224,6 +248,7 @@ class Session(object): | ||
| 224 | self.project_status = config.get('session', 'status') | 248 | self.project_status = config.get('session', 'status') |
| 225 | self.debug = config.get('session','debug') | 249 | self.debug = config.get('session','debug') |
| 226 | self.language = config.get('session','language') | 250 | self.language = config.get('session','language') |
| 251 | + self.random_id = config.get('session','random_id') | ||
| 227 | 252 | ||
| 228 | self.recent_projects = eval(config.get('project','recent_projects')) | 253 | self.recent_projects = eval(config.get('project','recent_projects')) |
| 229 | self.homedir = config.get('paths','homedir') | 254 | self.homedir = config.get('paths','homedir') |
| @@ -248,7 +273,8 @@ class Session(object): | @@ -248,7 +273,8 @@ class Session(object): | ||
| 248 | #Added to fix new version compatibility | 273 | #Added to fix new version compatibility |
| 249 | self.surface_interpolation = 0 | 274 | self.surface_interpolation = 0 |
| 250 | self.rendering = 0 | 275 | self.rendering = 0 |
| 251 | - | 276 | + self.random_id = randint(0,pow(10,16)) |
| 277 | + | ||
| 252 | self.CreateSessionFile() | 278 | self.CreateSessionFile() |
| 253 | return True | 279 | return True |
| 254 | 280 | ||
| @@ -281,6 +307,7 @@ class WriteSession(Thread): | @@ -281,6 +307,7 @@ class WriteSession(Thread): | ||
| 281 | config.set('session', 'status', self.session.project_status) | 307 | config.set('session', 'status', self.session.project_status) |
| 282 | config.set('session','debug', self.session.debug) | 308 | config.set('session','debug', self.session.debug) |
| 283 | config.set('session', 'language', self.session.language) | 309 | config.set('session', 'language', self.session.language) |
| 310 | + config.set('session', 'random_id', self.session.random_id) | ||
| 284 | config.set('session', 'surface_interpolation', self.session.surface_interpolation) | 311 | config.set('session', 'surface_interpolation', self.session.surface_interpolation) |
| 285 | config.set('session', 'rendering', self.session.rendering) | 312 | config.set('session', 'rendering', self.session.rendering) |
| 286 | 313 |
invesalius/utils.py
| @@ -366,4 +366,55 @@ def get_system_encoding(): | @@ -366,4 +366,55 @@ def get_system_encoding(): | ||
| 366 | 366 | ||
| 367 | 367 | ||
| 368 | 368 | ||
| 369 | +def UpdateCheck(): | ||
| 370 | + import urllib | ||
| 371 | + import urllib2 | ||
| 372 | + print "Checking updates..." | ||
| 373 | + | ||
| 374 | + # Check if there is a language set | ||
| 375 | + import i18n | ||
| 376 | + import session as ses | ||
| 377 | + session = ses.Session() | ||
| 378 | + install_lang = 0 | ||
| 379 | + if session.ReadLanguage(): | ||
| 380 | + lang = session.GetLanguage() | ||
| 381 | + if (lang != "False"): | ||
| 382 | + _ = i18n.InstallLanguage(lang) | ||
| 383 | + install_lang = 1 | ||
| 384 | + if (install_lang==0): | ||
| 385 | + return | ||
| 386 | + if session.ReadRandomId(): | ||
| 387 | + random_id = session.GetRandomId() | ||
| 388 | + | ||
| 389 | + # Fetch update data from server | ||
| 390 | + import constants as const | ||
| 391 | + url = "http://www.cti.gov.br/dt3d/invesalius/update/checkupdate.php" | ||
| 392 | + headers = { 'User-Agent' : 'Mozilla/5.0 (compatible; MSIE 5.5; Windows NT)' } | ||
| 393 | + data = {'update_protocol_version' : '1', | ||
| 394 | + 'invesalius_version' : const.INVESALIUS_VERSION, | ||
| 395 | + 'platform' : sys.platform, | ||
| 396 | + 'architecture' : platform.architecture()[0], | ||
| 397 | + 'language' : lang, | ||
| 398 | + 'random_id' : random_id } | ||
| 399 | + data = urllib.urlencode(data) | ||
| 400 | + req = urllib2.Request(url, data, headers) | ||
| 401 | + response = urllib2.urlopen(req) | ||
| 402 | + last = response.readline().rstrip() | ||
| 403 | + url = response.readline().rstrip() | ||
| 404 | + if (last!=const.INVESALIUS_VERSION+"1"): | ||
| 405 | + print " ...New update found!!! -> version:", last #, ", url=",url | ||
| 406 | + from time import sleep | ||
| 407 | + sleep(2) | ||
| 408 | + import wx | ||
| 409 | + app=wx.App() | ||
| 410 | + import i18n | ||
| 411 | + _ = i18n.InstallLanguage(lang) | ||
| 412 | + msg=_("A new version of InVesalius is available. Do you want to open the download website now?") | ||
| 413 | + title=_("Invesalius Update") | ||
| 414 | + msgdlg = wx.MessageDialog(None,msg,title, wx.YES_NO | wx.ICON_INFORMATION) | ||
| 415 | + if (msgdlg.ShowModal()==wx.ID_YES): | ||
| 416 | + wx.LaunchDefaultBrowser(url) | ||
| 417 | + msgdlg.Destroy() | ||
| 418 | + app.MainLoop() | ||
| 419 | + | ||
| 369 | 420 |