update.py
3.44 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
from version import TVersion
from frameUpdate import UpdateView
import wx
from DownloadFile import *
import Util
from wx.lib.pubsub import pub
import subprocess
import time
import os
class Update(object):
"""docstring for Update"""
def __init__(self, version,frame):
super(Update, self).__init__()
self.version = version
self.frame = frame
self.downloadFile = None
pub.subscribe(self.downloadSucess, "downloadSucess")
pub.subscribe(self.cancelDownload, "cancelDownload")
def cancelDownload(self,event):
if(self.frame.percentDownload>= 100):
if not (self.downloadFile == None):
self.downloadFile.stop()
self.frame.Destroy()
response = self.frame.showMessageDialog()
if (response == wx.ID_YES):
if not (self.downloadFile == None):
self.downloadFile.stop()
self.frame.Destroy()
self.frame.ShowMessage('Atualização Cancelada!')
else:
event.StopPropagation()
def stopDownload(self):
if not (self.downloadFile == None):
self.downloadFile.stop()
def startDownloadPlayer(self):
# #inicia o download do arquivo
self.downloadFile = DownloadFile2(version.url_download_player, Util.INSTALL_PLAYER_PATH)
self.downloadFile.start()
self.frame.txtInfo.SetLabel('Baixando a atualização...')
def startDownloadDict(self):
# #inicia o download do arquivo
self.downloadFile = DownloadFile2(version.url_download_dict, Util.DICTIONARY_ZIP_PATH)
self.downloadFile.start()
self.frame.txtInfo.SetLabel('Baixando a atualização...')
"""funcao chamada pelo DownloadFile quando terminado o download tanto do dicionario quanto do player"""
def downloadSucess(self, msg):
self.frame.Hide()
self.frame.txtInfo.SetLabel('Instalando Atualização...')
if(self.version.isUpdateDict()):
try:
Util.extractDictZip()
self.frame.ShowMessage('O Dicionário VLibras foi atualizado com sucesso!')
Util.updateFileDictVersion(self.version.api_dict_version_full)
except:
self.frame.ShowMessageError('Houve um erro ao atualizar o VLibras!')
elif (self.version.isUpdatePlayer()):
process = subprocess.call(Util.INSTALL_PLAYER_PATH)
time.sleep( 3 )
if os.path.isfile(Util.TEXT_CHECK_INSTALL):
self.frame.ShowMessage('O VLibras foi atualizado com sucesso!')
Util.updateFilePlayerVersion(self.version.api_player_version_full)
else:
self.frame.ShowMessageError('O VLibras não foi atualizado!')
subprocess.Popen(Util.PATH_PLAYER)
self.frame.Destroy()
if __name__ == '__main__':
app = wx.App(False)
frame = UpdateView()
version = TVersion()
#version.start()
frame.start()
update = Update(version,frame)
print version.checkVersion();
frame.closePulseDialog()
if(version.isUpdatePlayer()):
frame.Show()
update.startDownloadPlayer()
app.MainLoop()
elif(version.isUpdateDict()):
frame.Show()
update.startDownloadDict()
app.MainLoop()
else:
frame.ShowMessage('O VLibras está atualizado!')