Util.py 2.46 KB
# -*- 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()