2018-08-29 17:04:00 +02:00
"""
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * Projet CNI_Revelator * * *
GNU GPL * 07 / 2018
Adrien Bourmault
UPDATE
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"""
2019-06-30 17:54:41 +02:00
from CNI_GLOBALVAR import *
2018-08-29 17:04:00 +02:00
from CNI_classes import *
2019-06-30 17:54:41 +02:00
import hashlib
from pypac import PACSession
from requests . auth import HTTPProxyAuth
import subprocess
2018-08-29 17:04:00 +02:00
2019-06-30 17:54:41 +02:00
def SoftUpdate ( logger ) :
global ret
global upwin
2018-08-29 17:04:00 +02:00
import zipfile
2019-06-30 17:54:41 +02:00
for f in os . listdir ( CST_FOLDER ) :
if f [ - 4 : ] == ' .tif ' :
try :
os . remove ( CST_FOLDER + ' \\ ' + f )
except PermissionError as e :
logger . info ( ' SoftUpdate() : Failing to purge : ' + str ( e ) )
logger . info ( ' SoftUpdate() : Looking for older version in dir... ' )
2018-08-29 17:04:00 +02:00
list = os . listdir ( ' . ' )
for file in list :
2019-06-30 17:54:41 +02:00
if file . startswith ( ' CNIRevelator_ ' ) :
temp = [ ' 0 ' , ' 0 ' , ' 0 ' ]
ver = file [ 13 : ] . split ( ' . ' )
2018-08-29 17:04:00 +02:00
for i in range ( len ( ver ) ) :
2019-06-30 17:54:41 +02:00
if ver [ i ] != ' exe ' :
2018-08-29 17:04:00 +02:00
try :
temp [ i ] = ver [ i ]
except :
2019-06-30 17:54:41 +02:00
pass
2018-08-29 17:04:00 +02:00
ver = temp . copy ( )
2019-06-30 17:54:41 +02:00
try :
sum_ver = int ( ver [ 0 ] ) * 100 + int ( ver [ 1 ] ) * 10 + int ( ver [ 2 ] )
2018-08-29 17:04:00 +02:00
if sum_ver < CST_SUM_VER :
2019-06-30 17:54:41 +02:00
if file [ - 3 : ] == ' exe ' :
os . remove ( file )
logger . info ( ' SoftUpdate() : Removed old version : ' + str ( file ) )
CST_CHANGELOG . isOn = True
except Exception as e :
logger . error ( ' SoftUpdate() : Failing to remove old version ' + str ( file ) + ' : ' + str ( e ) )
def updating ( ) :
def updator ( ) :
2018-08-29 17:04:00 +02:00
global ret
2019-06-30 17:54:41 +02:00
logger . info ( ' [updator() thread] : Welcome ! ' )
2018-08-29 17:04:00 +02:00
ret = 11
2019-06-30 17:54:41 +02:00
canvas . itemconfigure ( message , text = ' Recherche de mises-à-jour... ' )
p . configure ( mode = ' indeterminate ' , value = 0 , maximum = 20 )
2018-08-29 17:04:00 +02:00
p . start ( )
upwin . update ( )
2019-06-30 17:54:41 +02:00
logger . info ( ' [updator() thread] : Looking for updates... ' )
try :
2018-08-29 17:04:00 +02:00
def download ( url , filename ) :
2019-06-30 17:54:41 +02:00
global key
global login
try :
logger . info ( ' [download() thread] : Trying getting credentials in the config file ' )
with open ( CST_FOLDER + ' conf.ig ' , ' rb ' ) as ( config ) :
AESObj = AESCipher ( CST_CRYPTOKEY )
try :
tempone = AESObj . decrypt ( config . read ( ) )
if tempone != ' || ' :
if tempone . find ( ' || ' ) != - 1 :
IPN , IPN_PASS = tempone . split ( ' || ' ) [ 0 : 2 ]
else :
raise ValueError ( ' Cryptokey is bad ! ' )
else :
IPN = ' '
IPN_PASS = ' '
except Exception as e :
raise IOError ( str ( e ) )
else :
logger . info ( ' [download() thread] : Got credentials ! ' )
session = PACSession ( proxy_auth = ( HTTPProxyAuth ( IPN , IPN_PASS ) ) )
logger . info ( ' [download() thread] : Authenticated to proxy successfully ' )
except IOError as e :
logger . error ( ' [download() thread] : False or absent credentials in the config file : ' + str ( e ) )
2018-08-29 17:04:00 +02:00
NoConnect = True
while NoConnect :
2019-06-30 17:54:41 +02:00
class LoginDialog ( Toplevel ) :
2018-08-29 17:04:00 +02:00
def __init__ ( self , parent ) :
super ( ) . __init__ ( parent )
2019-06-30 17:54:41 +02:00
self . title ( ' Connexion ' )
Label ( self , text = ' IPN : ' ) . pack ( )
2018-08-29 17:04:00 +02:00
self . entry_login = Entry ( self )
2019-06-30 17:54:41 +02:00
self . entry_login . insert ( 0 , ' ' )
2018-08-29 17:04:00 +02:00
self . entry_login . pack ( )
2019-06-30 17:54:41 +02:00
Label ( self , text = ' Mot de passe : ' ) . pack ( )
2018-08-29 17:04:00 +02:00
self . entry_pass = Entry ( self , show = ' * ' )
2019-06-30 17:54:41 +02:00
self . entry_pass . insert ( 0 , ' ' )
2018-08-29 17:04:00 +02:00
self . entry_pass . pack ( )
2019-06-30 17:54:41 +02:00
Button ( self , text = ' Connexion ' , command = ( self . connecti ) ) . pack ( )
2018-08-29 17:04:00 +02:00
self . resizable ( width = False , height = False )
w = 150
h = 110
2019-06-30 17:54:41 +02:00
self . update ( )
2018-08-29 17:04:00 +02:00
ws = self . winfo_screenwidth ( )
hs = self . winfo_screenheight ( )
2019-06-30 17:54:41 +02:00
if getattr ( sys , ' frozen ' , False ) :
self . iconbitmap ( sys . _MEIPASS + ' \\ id-card.ico \\ id-card.ico ' )
2018-08-29 17:04:00 +02:00
else :
2019-06-30 17:54:41 +02:00
self . iconbitmap ( ' id-card.ico ' )
upwin . update ( )
x = ws / 2 - w / 2
y = hs / 2 - h / 2
2018-08-29 17:04:00 +02:00
self . geometry ( ' %d x %d + %d + %d ' % ( w , h , x , y ) )
2019-06-30 17:54:41 +02:00
2018-08-29 17:04:00 +02:00
def connecti ( self ) :
global key
2019-06-30 17:54:41 +02:00
global login
2018-08-29 17:04:00 +02:00
login = self . entry_login . get ( ) . strip ( )
key = self . entry_pass . get ( ) . strip ( )
self . destroy ( )
2019-06-30 17:54:41 +02:00
2018-08-29 17:04:00 +02:00
session = PACSession ( )
if session . get_pac ( ) == None :
2019-06-30 17:54:41 +02:00
IPN = ' '
IPN_PASS = ' '
2018-08-29 17:04:00 +02:00
NoConnect = False
break
2019-06-30 17:54:41 +02:00
canvas . itemconfigure ( message , text = ' En attente de connexion au serveur proxy... ' )
login = ' '
key = ' '
2018-08-29 17:04:00 +02:00
result = LoginDialog ( upwin )
result . transient ( upwin )
result . grab_set ( )
upwin . wait_window ( result )
IPN = login
2019-06-30 17:54:41 +02:00
IPN_PASS = key
session = PACSession ( proxy_auth = ( HTTPProxyAuth ( IPN , IPN_PASS ) ) )
Ans = session . get ( ' http://www.google.com ' )
if str ( Ans ) == ' <Response [407]> ' :
canvas . itemconfigure ( message , text = ' Identifiants erronés, accès refusé ' )
logger . info ( ' [download() thread] : 407 Error ' )
2018-08-29 17:04:00 +02:00
time . sleep ( 1 )
else :
2019-06-30 17:54:41 +02:00
if str ( Ans ) == ' <Response [200]> ' :
logger . info ( ' [download() thread] : Connection ok ! ' )
NoConnect = False
else :
raise IOError ( )
AESObj = AESCipher ( CST_CRYPTOKEY )
with open ( CST_FOLDER + ' conf.ig ' , ' wb+ ' ) as ( f ) :
logger . info ( ' [download() thread] : Saving credentials in encrypted config file ' )
f . write ( AESObj . encrypt ( IPN + ' || ' + IPN_PASS ) )
if IPN == ' i005316 ' :
canvas . itemconfigure ( message , text = ' Bienvenue Thierry ! ' )
else :
if IPN == ' i020251 ' :
canvas . itemconfigure ( message , text = ' Bienvenue Samia ! ' )
else :
if IPN == ' i018410 ' :
canvas . itemconfigure ( message , text = ' Bienvenue Adrien ! ' )
else :
if IPN == ' i003067 ' :
canvas . itemconfigure ( message , text = ' Bienvenue Remy ! ' )
else :
if IPN == ' i018422 ' :
canvas . itemconfigure ( message , text = ' Bienvenue Eloise ! ' )
2018-08-29 17:04:00 +02:00
time . sleep ( 1 )
try :
2019-06-30 17:54:41 +02:00
Prox_us = session . get_pac ( ) . find_proxy_for_url ( CST_LINK , ' neoxgroup.eu ' )
PROXY_USABLE = Prox_us [ 6 : - 1 ] . split ( ' ; ' ) [ 0 ]
proxy_server_url = IPN + ' : ' + IPN_PASS + ' @ ' + PROXY_USABLE
ph = urllib2 . ProxyHandler ( { ' http ' : proxy_server_url } )
2018-08-29 17:04:00 +02:00
auth = urllib2 . ProxyBasicAuthHandler ( )
2019-06-30 17:54:41 +02:00
server = urllib2 . build_opener ( ph , auth , urllib2 . HTTPHandler )
2018-08-29 17:04:00 +02:00
urllib2 . install_opener ( server )
2019-06-30 17:54:41 +02:00
logger . info ( ' [download() thread] : Proxy connection initiated successfully ' )
2018-08-29 17:04:00 +02:00
except :
2019-06-30 17:54:41 +02:00
logger . info ( ' [download() thread] : Proxy connection not initiated ' )
2018-08-29 17:04:00 +02:00
try :
urllib2 . urlretrieve ( url , filename )
return True
except Exception as e :
2019-06-30 17:54:41 +02:00
logger . error ( ' [download() thread] : HTTP ERROR ' )
2018-08-29 17:04:00 +02:00
return e
2019-06-30 17:54:41 +02:00
logger . info ( ' [updator() thread] : Prepare downloading the version recap file... ' )
tempfile = CST_FOLDER + ' temp ' + str ( random . randint ( 11111 , 99999 ) ) + ' .cniu '
isOk = download ( CST_LINK + ' cnir.ver ' , tempfile )
2018-08-29 17:04:00 +02:00
if not isOk :
2019-06-30 17:54:41 +02:00
raise isOk
2018-08-29 17:04:00 +02:00
urllib2 . urlcleanup ( )
2019-06-30 17:54:41 +02:00
logger . info ( ' [updator() thread] : Opening version recap file... ' )
file_ver = open ( tempfile , ' r ' )
logger . info ( ' [updator() thread] : Reading version recap file... ' )
2018-08-29 17:04:00 +02:00
version = file_ver . read ( )
2019-06-30 17:54:41 +02:00
logger . info ( ' [updator() thread] : Closing version recap file... ' )
repert = version . split ( ' | ' )
2018-08-29 17:04:00 +02:00
file_ver . close ( )
2019-06-30 17:54:41 +02:00
logger . info ( ' [updator() thread] : Deleting version recap file... ' )
2018-08-29 17:04:00 +02:00
os . remove ( tempfile )
2019-06-30 17:54:41 +02:00
logger . info ( ' [updator() thread] : Parsing informations about version... ' )
final_f = ' CNI_file '
final_ver = [ ' 0 ' , ' 0 ' , ' 0 ' ]
final_hash = ' '
for sentence in repert :
2018-08-29 17:04:00 +02:00
try :
2019-06-30 17:54:41 +02:00
file , hashref = sentence . split ( ' : ' )
except ValueError :
pass
else :
if str . startswith ( file , CST_NAME ) :
ver = file . replace ( CST_NAME + ' _ ' , ' ' ) . split ( ' . ' )
temp = [
' 0 ' , ' 0 ' , ' 0 ' ]
for i in range ( len ( ver ) ) :
temp [ i ] = ver [ i ]
ver = temp . copy ( )
sum_fver = int ( final_ver [ 0 ] ) * 100 + int ( final_ver [ 1 ] ) * 10 + int ( final_ver [ 2 ] )
sum_ver = int ( ver [ 0 ] ) * 100 + int ( ver [ 1 ] ) * 10 + int ( ver [ 2 ] )
if sum_ver > sum_fver :
final_ver = ver . copy ( )
final_f = file
final_hash = hashref
sum_ver = int ( final_ver [ 0 ] ) * 100 + int ( final_ver [ 1 ] ) * 10 + int ( final_ver [ 2 ] )
if final_f != ' CNI_file ' :
if sum_ver > CST_SUM_VER :
logger . info ( ' [updator() thread] : New version of CNIRevelator found ! ' )
canvas . itemconfigure ( message , text = ' Mise à jour disponible ! Préparation du téléchargement... ' )
logger . info ( ' [updator() thread] : Preparing download ' )
with open ( CST_FOLDER + ' conf.ig ' , ' rb ' ) as ( config ) :
logger . info ( ' [updator() thread] : Reading credentials for proxy in config file... ' )
AESObj = AESCipher ( CST_CRYPTOKEY )
IPN , IPN_PASS = AESObj . decrypt ( config . read ( ) ) . split ( ' || ' ) [ 0 : 2 ]
session = PACSession ( proxy_auth = ( HTTPProxyAuth ( IPN , IPN_PASS ) ) )
2018-08-29 17:04:00 +02:00
try :
2019-06-30 17:54:41 +02:00
Prox_us = session . get_pac ( ) . find_proxy_for_url ( CST_LINK , ' neoxgroup.eu ' )
PROXY_USABLE = Prox_us [ 6 : - 1 ] . split ( ' ; ' ) [ 0 ]
proxy_server_url = IPN + ' : ' + IPN_PASS + ' @ ' + PROXY_USABLE
ph = urllib2 . ProxyHandler ( { ' http ' : proxy_server_url } )
auth = urllib2 . ProxyBasicAuthHandler ( )
server = urllib2 . build_opener ( ph , auth , urllib2 . HTTPHandler )
logger . info ( ' [updator() thread] : Connection to the proxy initiated successfully ! ' )
except :
canvas . itemconfigure ( message , text = ' Téléchargement en connexion directe... ' )
server = urllib2 . build_opener ( )
logger . info ( ' [updator() thread] : Direct connection initiated successfully ' )
logger . info ( ' [updator() thread] : Launching download of ' + final_f )
Statut = Download ( CST_LINK + final_f , final_f , final_f , server , p , canvas , message , logger )
BLOCKSIZE = 65536
hasher = hashlib . sha1 ( )
try :
with open ( final_f , ' rb ' ) as ( afile ) :
buf = afile . read ( BLOCKSIZE )
while len ( buf ) > 0 :
hasher . update ( buf )
buf = afile . read ( BLOCKSIZE )
hashcod = hasher . hexdigest ( )
if hashcod != final_hash :
Statut . success = False
logger . error ( ' [updator() thread] : Hashcode Error : ' + final_f )
try :
os . remove ( final_f )
except IOError :
pass
else :
logger . info ( ' [updator() thread] : Hashcode pass : ' + final_f )
except FileNotFoundError as e :
logger . error ( ' [updator() thread] : File not found ' + final_f )
if Statut . success :
2018-08-29 17:04:00 +02:00
try :
2019-06-30 17:54:41 +02:00
os . rename ( final_f , final_f + ' .exe ' )
2018-08-29 17:04:00 +02:00
except IOError :
2019-06-30 17:54:41 +02:00
logger . error ( ' [updator() thread] : Unable to rename the file ! Wait 3 sec and retry ' )
2018-08-29 17:04:00 +02:00
time . sleep ( 3 )
try :
2019-06-30 17:54:41 +02:00
os . rename ( final_f , final_f + ' .exe ' )
except IOError :
logger . critical ( ' [updator() thread] : Unable to rename the file ! ' )
else :
canvas . itemconfigure ( message , text = ' Téléchargement terminé ! Préparation du lancement... ' )
logger . info ( ' [updator() thread] : Download of ' + final_f + ' finished successfully ' )
p . configure ( mode = ' indeterminate ' , value = 0 , maximum = 20 )
p . start ( )
time . sleep ( 1 )
logger . info ( ' [updator() thread] : Launching ' + final_f )
try :
proc = subprocess . Popen ( ( final_f + ' .exe ' ) , shell = False , stdin = None , stdout = None , stderr = None , close_fds = True )
except :
logger . error ( ' [updator() thread] : Unable to start the new version ! Wait 3 sec and retry ' )
time . sleep ( 3 )
try :
proc = subprocess . Popen ( ( final_f + ' .exe ' ) , shell = False , stdin = None , stdout = None , stderr = None , close_fds = True )
except Exception as e :
logger . critical ( ' [updator() thread] : Unable to start the new version ! Stopping : ' + str ( e ) )
showerror ( " Erreur d ' appel de procédure distante " , ' Le lancement du nouveau programme a échoué, vous devez le lancer manuellement une fois cette fenêtre fermée ' , parent = upwin )
ret = 12
else :
canvas . itemconfigure ( message , text = ' Echec de la mise à jour : Erreur HTTP. Préparation du lancement... ' )
logger . error ( ' [updator() thread] : Update has failed with HTTP error ' )
time . sleep ( 1 )
canvas . itemconfigure ( message , text = ' Logiciel déjà à jour. Préparation du lancement... ' )
logger . info ( ' [updator() thread] : CNIRevelator is up to date ! ' )
2018-08-29 17:04:00 +02:00
time . sleep ( 1 )
ret = 11
2019-06-30 17:54:41 +02:00
if os . path . exists ( CST_FOLDER + ' Tesseract-OCR4 \\ tesseract.exe ' ) :
os . environ [ ' PATH ' ] = CST_FOLDER + ' Tesseract-OCR4 \\ '
os . environ [ ' TESSDATA_PREFIX ' ] = CST_FOLDER + ' Tesseract-OCR4 \\ tessdata '
2018-08-29 17:04:00 +02:00
else :
2019-06-30 17:54:41 +02:00
final_f = ' tesseract_4 '
logger . info ( ' [updator() thread] : Downloading tesseract 4 ! ' )
canvas . itemconfigure ( message , text = ' Mise à jour du module OCR ! Préparation du téléchargement... ' )
logger . info ( ' [updator() thread] : Preparing download ' )
with open ( CST_FOLDER + ' conf.ig ' , ' rb ' ) as ( config ) :
logger . info ( ' [updator() thread] : Reading credentials for proxy in config file... ' )
AESObj = AESCipher ( CST_CRYPTOKEY )
IPN , IPN_PASS = AESObj . decrypt ( config . read ( ) ) . split ( ' || ' ) [ 0 : 2 ]
session = PACSession ( proxy_auth = ( HTTPProxyAuth ( IPN , IPN_PASS ) ) )
2018-08-29 17:04:00 +02:00
try :
2019-06-30 17:54:41 +02:00
Prox_us = session . get_pac ( ) . find_proxy_for_url ( CST_LINK , ' neoxgroup.eu ' )
PROXY_USABLE = Prox_us [ 6 : - 1 ] . split ( ' ; ' ) [ 0 ]
proxy_server_url = IPN + ' : ' + IPN_PASS + ' @ ' + PROXY_USABLE
ph = urllib2 . ProxyHandler ( { ' http ' : proxy_server_url } )
2018-08-29 17:04:00 +02:00
auth = urllib2 . ProxyBasicAuthHandler ( )
2019-06-30 17:54:41 +02:00
server = urllib2 . build_opener ( ph , auth , urllib2 . HTTPHandler )
logger . info ( ' [updator() thread] : Connection to the proxy initiated successfully ! ' )
2018-08-29 17:04:00 +02:00
except :
2019-06-30 17:54:41 +02:00
canvas . itemconfigure ( message , text = ' Téléchargement en connexion directe... ' )
server = urllib2 . build_opener ( )
logger . info ( ' [updator() thread] : Direct connection initiated successfully ' )
logger . info ( ' [updator() thread] : Launching download of ' + final_f )
Statut = Download ( CST_LINK + final_f , CST_FOLDER + final_f , final_f , server , p , canvas , message , logger )
hashcod = ' '
logger . info ( ' [updator() thread] : Verifying hashcode of ' + final_f )
BLOCKSIZE = 65536
hasher = hashlib . sha1 ( )
try :
with open ( CST_FOLDER + final_f , ' rb ' ) as ( afile ) :
buf = afile . read ( BLOCKSIZE )
while len ( buf ) > 0 :
hasher . update ( buf )
buf = afile . read ( BLOCKSIZE )
hashcod = hasher . hexdigest ( )
if hashcod != CST_TesserHash :
Statut . success = False
logger . error ( ' [updator() thread] : Hashcode Error : ' + final_f )
try :
os . remove ( CST_FOLDER + final_f )
except IOError :
pass
else :
logger . info ( ' [updator() thread] : Hashcode pass : ' + final_f )
except FileNotFoundError as e :
logger . error ( ' [updator() thread] : File not found ' + final_f )
2018-08-29 17:04:00 +02:00
if Statut . success :
2019-06-30 17:54:41 +02:00
canvas . itemconfigure ( message , text = ' Téléchargement terminé ! Installation... ' )
logger . info ( ' [updator() thread] : Download of ' + final_f + ' finished successfully ' )
p . configure ( mode = ' indeterminate ' , value = 0 , maximum = 20 )
2018-08-29 17:04:00 +02:00
p . start ( )
try :
zip_ref = zipfile . ZipFile ( CST_FOLDER + final_f , ' r ' )
zip_ref . extractall ( CST_FOLDER )
zip_ref . close ( )
2019-06-30 17:54:41 +02:00
os . environ [ ' PATH ' ] = CST_FOLDER + ' Tesseract-OCR4 \\ '
os . environ [ ' TESSDATA_PREFIX ' ] = CST_FOLDER + ' Tesseract-OCR4 \\ tessdata '
canvas . itemconfigure ( message , text = ' Installation terminée ! ' )
2018-08-29 17:04:00 +02:00
except :
2019-06-30 17:54:41 +02:00
logger . error ( ' [updator() thread] : Unable to install the module. Wait and retry ' )
2018-08-29 17:04:00 +02:00
time . sleep ( 3 )
try :
zip_ref = zipfile . ZipFile ( CST_FOLDER + final_f , ' r ' )
zip_ref . extractall ( CST_FOLDER )
zip_ref . close ( )
2019-06-30 17:54:41 +02:00
os . environ [ ' PATH ' ] = CST_FOLDER + ' Tesseract-OCR4 \\ '
os . environ [ ' TESSDATA_PREFIX ' ] = CST_FOLDER + ' Tesseract-OCR4 \\ tessdata '
canvas . itemconfigure ( message , text = ' Installation terminée ! ' )
2018-08-29 17:04:00 +02:00
except Exception as e :
2019-06-30 17:54:41 +02:00
logger . critical ( ' [updator() thread] : Unable to install the module ! Stopping : ' + str ( e ) )
2018-08-29 17:04:00 +02:00
showerror ( " Erreur d ' appel de procédure distante " , " L ' installation du module OCR a échoué, contactez le développeur. " )
2019-06-30 17:54:41 +02:00
2018-08-29 17:04:00 +02:00
ret = 11
else :
2019-06-30 17:54:41 +02:00
logger . critical ( ' [updator() thread] : Unable to download the module ! ' )
showerror ( ' Erreur de téléchargement ' , " L ' installation du module OCR a échoué, merci d ' indiquer le chemin d ' accès au fichier tesseract_4 dans la fenêtre suivante " )
path = filedialog . askopenfilename ( title = " Indiquez le chemin d ' accès à tesseract_4... " , filetypes = ( ( ' Tesseract_4 ' , ' *.cni4 ' ) ,
( ' Tesseract_4 ' , ' *.cni4 ' ) ) )
if path != ' ' :
2018-08-29 17:04:00 +02:00
try :
2019-06-30 17:54:41 +02:00
canvas . itemconfigure ( message , text = ' Installation... ' )
2018-08-29 17:04:00 +02:00
zip_ref = zipfile . ZipFile ( path , ' r ' )
zip_ref . extractall ( CST_FOLDER )
zip_ref . close ( )
2019-06-30 17:54:41 +02:00
logger . error ( ' [updator() thread] : Manual installation successed ' )
canvas . itemconfigure ( message , text = ' Installation terminée ! ' )
os . environ [ ' PATH ' ] = CST_FOLDER + ' Tesseract-OCR4 \\ '
os . environ [ ' TESSDATA_PREFIX ' ] = CST_FOLDER + ' Tesseract-OCR4 \\ tessdata '
2018-08-29 17:04:00 +02:00
except Exception as e :
2019-06-30 17:54:41 +02:00
logger . error ( ' [updator() thread] : Manual installation has failed ' + str ( e ) )
showerror ( ' Erreur de lecture ' , " Le module OCR n ' a pas pu être installé, la saisie automatique de scans ne pourra donc fonctionner " )
2018-08-29 17:04:00 +02:00
else :
2019-06-30 17:54:41 +02:00
showerror ( ' Opération annulée ' , " Le module OCR n ' a été installé, la saisie automatique de scans ne pourra donc fonctionner " )
2018-08-29 17:04:00 +02:00
except URLExcept . HTTPError as e :
2019-06-30 17:54:41 +02:00
canvas . itemconfigure ( message , text = ( ' Echec de la mise à jour : Erreur HTTP ' + str ( e . code ) + ' . Préparation du lancement... ' ) )
logger . error ( ' [updator() thread] : Update has failed with HTTP error ' + str ( e . code ) )
2018-08-29 17:04:00 +02:00
if int ( e . code ) == 407 :
2019-06-30 17:54:41 +02:00
showerror ( ' Erreur 407 ' , ' Attention : le système de mise à jour automatique a fait face à une erreur 407, signifiant que la connexion au serveur proxy a été refusée. Vos identifiants vous seront redemandés au prochain démarrage. La mise à jour a échoué. ' )
logger . info ( ' [updator() thread] : Credential error. Deleting the config file... ' )
os . remove ( CST_FOLDER + ' conf.ig ' )
p . configure ( mode = ' indeterminate ' , value = 0 , maximum = 20 )
2018-08-29 17:04:00 +02:00
p . start ( )
time . sleep ( 3 )
except Exception as e :
2019-06-30 17:54:41 +02:00
canvas . itemconfigure ( message , text = ' Echec de la mise à jour. Préparation du lancement... ' )
logger . error ( ' [updator() thread] : Error from the updating system : ' + str ( e ) )
p . configure ( mode = ' indeterminate ' , value = 0 , maximum = 20 )
2018-08-29 17:04:00 +02:00
p . start ( )
time . sleep ( 2 )
2019-06-30 17:54:41 +02:00
2018-08-29 17:04:00 +02:00
p . stop ( )
upwin . destroy ( )
root . destroy ( )
return ret
2019-06-30 17:54:41 +02:00
logger . info ( ' updating() : Launching updator() thread... ' )
2018-08-29 17:04:00 +02:00
threading . Thread ( target = updator , daemon = True ) . start ( )
2019-06-30 17:54:41 +02:00
logger . info ( ' updating() [Thread] : Ending updator() thread ' )
2018-08-29 17:04:00 +02:00
ret = 11
root = Tk ( )
2019-06-30 17:54:41 +02:00
root . attributes ( ' -alpha ' , 0.0 )
2018-08-29 17:04:00 +02:00
root . iconify ( )
upwin = Toplevel ( root )
upwin . overrideredirect ( 1 )
2019-06-30 17:54:41 +02:00
upwin . configure ( bg = CST_COLOR )
2018-08-29 17:04:00 +02:00
upwin . resizable ( width = False , height = False )
w = 600
h = 300
2019-06-30 17:54:41 +02:00
upwin . update ( )
2018-08-29 17:04:00 +02:00
canvas = Canvas ( upwin , width = 600 , height = 270 , bg = CST_COLOR , highlightthickness = 0 )
pbar = Canvas ( upwin , width = 600 , height = 30 , bg = CST_COLOR )
p = ttk . Progressbar ( pbar , orient = HORIZONTAL , length = 590 , mode = ' determinate ' )
upwin . update ( )
ws = upwin . winfo_screenwidth ( )
hs = upwin . winfo_screenheight ( )
2019-06-30 17:54:41 +02:00
canvas . create_text ( ( w / 2 ) , ( h / 3 ) , text = ( CST_NAME + ' ' + CST_VERTITLE ) , font = ' Calibri 30 bold ' , fill = ' white ' )
message = canvas . create_text ( ( w / 2 ) , ( h / 1.15 ) , text = ' ' , font = ' Calibri 9 ' , fill = ' white ' )
upwin . update ( )
x = ws / 2 - w / 2
y = hs / 2 - h / 2
2018-08-29 17:04:00 +02:00
upwin . geometry ( ' %d x %d + %d + %d ' % ( w , h , x , y ) )
canvas . grid ( )
pbar . grid ( )
p . grid ( )
upwin . after ( 2000 , updating )
2019-06-30 17:54:41 +02:00
if getattr ( sys , ' frozen ' , False ) :
root . iconbitmap ( sys . _MEIPASS + ' \\ id-card.ico \\ id-card.ico ' )
2018-08-29 17:04:00 +02:00
else :
2019-06-30 17:54:41 +02:00
root . iconbitmap ( ' id-card.ico ' )
logger . info ( ' SoftUpdate() : Entering upwin mainloop() ' )
upwin . protocol ( ' WM_DELETE_WINDOW ' , lambda : root . destroy ( ) )
2018-08-29 17:04:00 +02:00
upwin . mainloop ( )
2019-06-30 17:54:41 +02:00
logger . info ( ' SoftUpdate() : Exiting upwin mainloop() ' )
2018-08-29 17:04:00 +02:00
if ret == 11 :
2019-06-30 17:54:41 +02:00
logger . info ( ' SoftUpdate() : OK to start to main() normally ! ' )
2018-08-29 17:04:00 +02:00
return True
else :
2019-06-30 17:54:41 +02:00
logger . info ( ' SoftUpdate() : Program will stop ! ' )
2018-08-29 17:04:00 +02:00
return False