VlibrasUpdate.py 3.25 KB
# -*- coding: cp1252 -*-
import json, zipfile, subprocess,urllib
from os import popen
from threading import Thread
from VlibrasUpdateInstall import*

url_download_player =''
url_download_dict =''
PATH_RESOURCE = 'C:/vlibras-libs/update/'
JSON_LOCAL_NAME = 'version/version.json'
JSON_API_NAME = 'download/versionApi.json'
PLAYER_DICT_UPDATE_PATH = PATH_RESOURCE+'bin/vlibrasPlayerDictUp.exe '
DICTIONARY_NAME = 'download/vlibras_dicionario.zip'
INSTALL_PLAYER_NAME = 'download/Vlibras_Up.exe'
URL_REQUEST_API = 'http://vlibras.lavid.ufpb.br/api/dicionario/'
DICTIONARY_EXTRACT_PATH = 'C:/vlibras-libs/Player/VLibrasPlayer_Data/Bundles'



   

    
def checkVersion():
	
##    try:
##
##        with open(PATH_RESOURCE+JSON_LOCAL_NAME) as data_file:
##                json_data = json.load(data_file)
##
##        my_dict_version_full = json_data['dictionaryVersion'].encode('utf-8')
##        my_player_version = json_data['playerVersion'].encode('utf-8').replace(".", "")
##        my_dict_version = my_dict_version_full.replace(".", "").replace("_", "")  
##
##        if(not downladFileApi(URL_REQUEST_API+my_dict_version_full+'?type=linux')):
##            return 'erro'
##        
##        with open(PATH_RESOURCE+JSON_API_NAME) as data:
##                json_data = json.load(data)
##        
##        api_dict_version = json_data['dictionaryVersion'].encode('utf-8').replace(".", "").replace("_", "")
##        api_player_version = json_data['playerVersion'].encode('utf-8').replace(".", "")
##        url_download_player = json_data['playerUrl'].encode('utf-8')
##        url_download_dict = json_data['dictionaryUrl'].encode('utf-8')
##        
##        
##        if int(api_player_version) > int(my_player_version): 
##            return url_download_player
##                
##        elif int(api_dict_version) > int(my_dict_version):
##                
##            return url_download_dict
##        
##        else: 
##            return "atualizado"
##
##    except:
        
        return "erro"	
         

def downladFileApi(_url):
    try:
        
        urllib.urlretrieve (_url, PATH_RESOURCE+JSON_API_NAME)
        
        return True
    except:
        return False
    	
def installPlayer():
    try:
##        with open(PATH_RESOURCE+JSON_API_NAME) as data:
##                json_data = json.load(data)
                
##        url_download_player = json_data['playerUrl'].encode('utf-8')
        # install = CallInstall()
        # install.start()
       process = subprocess.Popen(["C:\\Python27\\python.exe", "c:\\vlibras-libs\\update\\py\\VlibrasUpdateInstall.pyc"])
##        update_json_file()
    except Exception, e:
        print e
        return -1
    return 1

def installDict():
    try:
##        install = CallInstall()
##        install.start()

       process = subprocess.Popen(["C:\\Python27\\python.exe", "c:\\vlibras-libs\\update\\py\\VlibrasUpdateInstall.pyc"])
##        with open(PATH_RESOURCE+JSON_API_NAME) as data:
##                json_data = json.load(data)
##        url_download_dict = json_data['dictionaryUrl'].encode('utf-8')
##        process = subprocess.Popen(PLAYER_DICT_UPDATE_PATH+url_download_dict)
    except Exception, e:
        print e
        return -1
    return 1


if __name__ == '__main__':
    print installPlayer()