Util.py
2.46 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
# -*- coding: utf-8 -*-
import os.path
import json, zipfile, subprocess,urllib
from os import popen
import sys , shutil
import wx
PATH_RESOURCE = os.getenv("ProgramFiles")+'/VLibras/'
DICTIONARY_EXTRACT_PATH = PATH_RESOURCE+'/Player/VLibrasPlayer_Data/Bundles'
DICTIONARY_ZIP_PATH = PATH_RESOURCE+'update/download/vlibras_dicionario.zip'
TXT_DICT_VERSION = PATH_RESOURCE+'update/version/dictVersion.txt'
TXT_PLAYER_VERSION = PATH_RESOURCE+'update/version/playerVersion.txt'
TXT_PLAYER_VERSION_DOWNLOAD = PATH_RESOURCE+'update/version/DownloadPlayerVersion.txt'
JSON_API_VERSION = PATH_RESOURCE+'update/download/versionApi.json'
URL_REQUEST_API = 'http://vlibras.lavid.ufpb.br/api/dicionario/'
TEXT_CHECK_INSTALL = PATH_RESOURCE+'installSucess.txt'
INSTALL_PLAYER_PATH = PATH_RESOURCE+'update/download/Vlibras_Up.exe'
PATH_PLAYER = PATH_RESOURCE+'Player/VlibrasPlayer.exe'
ICON = PATH_RESOURCE+'icons/icon_vlibras.ico'
## atualiza a versão do arquivo de dicionario
def updateFileDictVersion(version):
try:
txt_local_version = open(TXT_DICT_VERSION, 'w')
txt_local_version.write(version)
txt_local_version.close()
return True
except:
return False
## artualiza a versão do arquivo de player
def updateFilePlayerVersion(version):
try:
if os.path.isfile(TXT_PLAYER_VERSION):
txt_local_version = open(TXT_PLAYER_VERSION, 'w')
txt_local_version.write(version)
txt_local_version.close()
return True
else:
return False
except:
return False
## apos atualizar, criar arquivo de sucesso
##e move o atualizador do player para fora da pasta original para que o desinstalador não cause problema
def updateSuccess():
txt_local_version = open(TEXT_CHECK_INSTALL, 'w')
txt_local_version.write('sucess')
txt_local_version.close()
shutil.move(PATH_RESOURCE+'update/bin/vlibrasPlayerUp.exe', PATH_RESOURCE+'update/')
## faz dawnload do json das versões
def downladFileApi(_url):
try:
urllib.urlretrieve (_url, JSON_API_VERSION)
return True
except Exception, e:
print e
return False
def extractDictZip():
dlg = wx.ProgressDialog("Atualização VLibras", "Finalizando Atualização...", style = wx.PD_APP_MODAL)
dlg.Pulse()
with zipfile.ZipFile(DICTIONARY_ZIP_PATH, "r") as z:
z.extractall(DICTIONARY_EXTRACT_PATH)
dlg.Destroy()