mirror of
https://gitlab.os-k.eu/neox/CNIRevelator.git
synced 2023-08-25 14:03:10 +02:00
Finished work on Update System
This commit is contained in:
parent
a101664f6e
commit
cdbe83b789
@ -28,30 +28,32 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
|
import psutil
|
||||||
|
|
||||||
import launcher # launcher.py
|
import launcher # launcher.py
|
||||||
import ihm # ihm.py
|
import updater # updater.py
|
||||||
import logger # logger.py
|
import globs # globs.py
|
||||||
import updater # updater.py
|
import pytesseract # pytesseract.py
|
||||||
import globs # globs.py
|
|
||||||
|
|
||||||
## MAIN FUNCTION OF CNIREVELATOR
|
## MAIN FUNCTION OF CNIREVELATOR
|
||||||
def main():
|
def main():
|
||||||
|
import logger # logger.py
|
||||||
|
logfile = logger.logMain
|
||||||
|
|
||||||
import CNI_pytesseract as pytesseract
|
|
||||||
try:
|
try:
|
||||||
os.environ['PATH'] = CST_FOLDER + 'Tesseract-OCR4\\'
|
os.environ['PATH'] = globs.CNIRFolder + '\\Tesseract-OCR4\\'
|
||||||
os.environ['TESSDATA_PREFIX'] = CST_FOLDER + 'Tesseract-OCR4\\tessdata'
|
os.environ['TESSDATA_PREFIX'] = globs.CNIRFolder + '\\Tesseract-OCR4\\tessdata'
|
||||||
tesser_version = pytesseract.get_tesseract_version()
|
tesser_version = pytesseract.get_tesseract_version()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('main() : **** ERROR WITH TESSERACT MODULE ' + str(e) + ' ****')
|
logfile.printerr('ERROR WITH TESSERACT MODULE ' + str(e))
|
||||||
else:
|
else:
|
||||||
text = 'Tesseract version ' + str(tesser_version) + ' Licensed Apache 2004 successfully initiated\n'
|
text = 'Tesseract version ' + str(tesser_version) + ' Licensed Apache 2004 successfully initiated\n'
|
||||||
main_w.montext(text)
|
main_w.montext(text)
|
||||||
|
|
||||||
main_w.montext('\n\nEntrez la première ligne de MRZ svp \n')
|
main_w.montext('\n\nEntrez la première ligne de MRZ svp \n')
|
||||||
|
|
||||||
if CST_CHANGELOG.isOn:
|
if globs.CNIRNewVersion:
|
||||||
showinfo('Changelog : résumé de mise à jour', ('Version du logiciel : ' + CST_VER + ' ' + CST_TYPE + ' Revision ' + CST_REV + '\n\n' + CST_CHANGELOG.text), parent=main_w)
|
showinfo('Changelog : résumé de mise à jour', ('Version du logiciel : CNIRevelator ' + globs.verstring_full + '\n\n' + globs.changelog), parent=main_w)
|
||||||
logger.info('main() : **** Launching App_main() ****')
|
logger.info('main() : **** Launching App_main() ****')
|
||||||
main_w.mainloop()
|
main_w.mainloop()
|
||||||
logger.info('main() : **** Ending App_main() ****')
|
logger.info('main() : **** Ending App_main() ****')
|
||||||
@ -78,6 +80,13 @@ if updater.UPDATE_IS_MADE:
|
|||||||
break
|
break
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
#main()
|
# Here we go !
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except Exception:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
sys.exit(0)
|
# Quit totally without remain in memory
|
||||||
|
for process in psutil.process_iter():
|
||||||
|
if process.pid == os.getpid():
|
||||||
|
process.terminate()
|
@ -36,10 +36,12 @@ CNIRFolder = os.getcwd()
|
|||||||
CNIRLColor = "#006699"
|
CNIRLColor = "#006699"
|
||||||
CNIRName = "CNIRevelator {}".format(verstring)
|
CNIRName = "CNIRevelator {}".format(verstring)
|
||||||
CNIRCryptoKey = '82Xh!efX3#@P~2eG'
|
CNIRCryptoKey = '82Xh!efX3#@P~2eG'
|
||||||
|
CNIRNewVersion = False
|
||||||
|
|
||||||
CNIRConfig = CNIRFolder + '\\config\\conf.ig'
|
CNIRConfig = CNIRFolder + '\\config\\conf.ig'
|
||||||
CNIRErrLog = CNIRFolder + '\\logs\\error.log'
|
CNIRErrLog = CNIRFolder + '\\logs\\error.log'
|
||||||
CNIRLauncherLog = CNIRFolder + '\\logs\\launcher.log'
|
CNIRLauncherLog = CNIRFolder + '\\logs\\launcher.log'
|
||||||
|
CNIRMainLog = CNIRFolder + '\\logs\\main.log'
|
||||||
CNIRUrlConfig = CNIRFolder + '\\config\\urlconf.ig'
|
CNIRUrlConfig = CNIRFolder + '\\config\\urlconf.ig'
|
||||||
CNIRVerStock = CNIRFolder + '\\downloads\\versions.lst'
|
CNIRVerStock = CNIRFolder + '\\downloads\\versions.lst'
|
||||||
CNIREnv = os.getenv('APPDATA') + '/CNIRevelator/'
|
CNIREnv = os.getenv('APPDATA') + '/CNIRevelator/'
|
||||||
|
@ -64,5 +64,33 @@ class NewLoggingSystem:
|
|||||||
def close(self):
|
def close(self):
|
||||||
logging.shutdown()
|
logging.shutdown()
|
||||||
|
|
||||||
|
class NewMainLoggingSystem:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
# Create new logging handle
|
||||||
|
logger = logging.getLogger()
|
||||||
|
logger.setLevel(logging.INFO) # To make sure we can have a debug channel
|
||||||
|
|
||||||
|
# Create channels
|
||||||
|
formatter = logging.Formatter("\n[ %(module)s/%(funcName)s ] %(asctime)s :: %(levelname)s :: %(message)s")
|
||||||
|
error_handler = logging.FileHandler((globs.CNIRErrLog), mode='w', encoding='utf-8', delay=True)
|
||||||
|
info_handler = logging.FileHandler((globs.CNIRMainLog), mode='w', encoding='utf-8')
|
||||||
|
|
||||||
|
error_handler.setLevel(logging.ERROR)
|
||||||
|
error_handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(error_handler)
|
||||||
|
|
||||||
|
info_handler.setLevel(logging.DEBUG)
|
||||||
|
info_handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(info_handler)
|
||||||
|
|
||||||
|
self.logger = logger
|
||||||
|
self.printerr = logger.error
|
||||||
|
self.printdbg = logger.info
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
logging.shutdown()
|
||||||
|
|
||||||
## Global Handler
|
## Global Handler
|
||||||
logCur = NewLoggingSystem()
|
logCur = NewLoggingSystem()
|
||||||
|
logMain = NewMainLoggingSystem()
|
||||||
|
@ -25,6 +25,10 @@
|
|||||||
|
|
||||||
from PIL import Image, ImageFont, ImageDraw, ImageTk, ImageEnhance, ImageFilter
|
from PIL import Image, ImageFont, ImageDraw, ImageTk, ImageEnhance, ImageFilter
|
||||||
import math, warnings, string
|
import math, warnings, string
|
||||||
|
from tkinter import *
|
||||||
|
from tkinter.messagebox import *
|
||||||
|
from tkinter import filedialog
|
||||||
|
from tkinter import ttk
|
||||||
|
|
||||||
import mrz # mrz.py
|
import mrz # mrz.py
|
||||||
from image import CanvasImage # image.py
|
from image import CanvasImage # image.py
|
||||||
|
@ -183,11 +183,30 @@ def batch():
|
|||||||
# Move to the right place
|
# Move to the right place
|
||||||
shutil.copytree(UPATH + 'temp\\CNIRevelator', UPATH)
|
shutil.copytree(UPATH + 'temp\\CNIRevelator', UPATH)
|
||||||
shutil.rmtree(UPATH + 'temp')
|
shutil.rmtree(UPATH + 'temp')
|
||||||
|
logfile.printdbg('Extracted :' + UPATH + '\\CNIRevelator.exe')
|
||||||
logfile.printdbg('Extracted :' + UPATH + '\\CNIRevelator.exe')
|
|
||||||
|
|
||||||
launcherWindow.printmsg('Success !')
|
launcherWindow.printmsg('Success !')
|
||||||
|
|
||||||
|
# Verifying that Tesseract is installed
|
||||||
|
if not os.path.exists(globs.CNIRFolder + '\\Tesseract-OCR4\\'):
|
||||||
|
tesseracturl = finalurl.replace("CNIRevelator.zip", "tesseract_4.zip")
|
||||||
|
# WE ASSUME THAT THE MAIN FILE IS CNIRevelator.zip AND THAT THE TESSERACT PACKAGE IS tesseract_4.zip
|
||||||
|
logfile.printdbg('Preparing download of Tesseract OCR 4...')
|
||||||
|
getTesseract = downloader.newdownload(credentials, tesseracturl, UPATH + '\\TsrtPackage.zip').download()
|
||||||
|
|
||||||
|
# Unzip Tesseract
|
||||||
|
logfile.printdbg("Unzipping the package")
|
||||||
|
launcherWindow.printmsg('Installing the updates')
|
||||||
|
zip_ref = zipfile.ZipFile(UPATH + '\\TsrtPackage.zip', 'r')
|
||||||
|
zip_ref.extractall(UPATH)
|
||||||
|
zip_ref.close()
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
try:
|
||||||
|
os.remove(UPATH + '\\TsrtPackage.zip')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
try:
|
try:
|
||||||
os.remove(globs.CNIRFolder + '\\..\\CNIPackage.zip')
|
os.remove(globs.CNIRFolder + '\\..\\CNIPackage.zip')
|
||||||
@ -208,6 +227,7 @@ def umain():
|
|||||||
|
|
||||||
# Cleaner for the old version if detected
|
# Cleaner for the old version if detected
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
|
globs.CNIRNewVersion = True
|
||||||
launcherWindow.printmsg('Deleting old version !')
|
launcherWindow.printmsg('Deleting old version !')
|
||||||
logfile.printdbg("Old install detected : {}".format(sys.argv[1]))
|
logfile.printdbg("Old install detected : {}".format(sys.argv[1]))
|
||||||
while os.path.exists(str(sys.argv[1])):
|
while os.path.exists(str(sys.argv[1])):
|
||||||
|
Loading…
Reference in New Issue
Block a user