2019-07-09 16:13:16 +02:00
|
|
|
"""
|
|
|
|
********************************************************************************
|
|
|
|
* CNIRevelator *
|
|
|
|
* *
|
|
|
|
* Desc: Application launcher & updater *
|
|
|
|
* *
|
|
|
|
* Copyright © 2018-2019 Adrien Bourmault (neox95) *
|
|
|
|
* *
|
2019-08-06 16:01:01 +02:00
|
|
|
* *
|
2019-07-09 16:13:16 +02:00
|
|
|
* This file is part of CNIRevelator. *
|
|
|
|
* *
|
|
|
|
* CNIRevelator is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* any later version. *
|
|
|
|
* *
|
|
|
|
* CNIRevelator is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY*without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with CNIRevelator. If not, see <https:*www.gnu.org/licenses/>. *
|
|
|
|
********************************************************************************
|
|
|
|
"""
|
|
|
|
|
2019-07-09 23:01:09 +02:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import threading
|
2019-07-11 11:16:41 +02:00
|
|
|
import psutil
|
2019-08-12 17:07:37 +02:00
|
|
|
from tkinter import *
|
|
|
|
from tkinter.messagebox import *
|
2019-07-09 16:13:16 +02:00
|
|
|
|
2019-08-10 19:59:16 +02:00
|
|
|
import launcher # launcher.py"
|
2019-07-11 11:16:41 +02:00
|
|
|
import updater # updater.py
|
|
|
|
import globs # globs.py
|
|
|
|
import pytesseract # pytesseract.py
|
2019-07-12 10:57:03 +02:00
|
|
|
import logger # logger.py
|
2019-08-12 17:07:37 +02:00
|
|
|
import lang # lang.py
|
|
|
|
import ihm # ihm.py
|
2019-07-12 10:57:03 +02:00
|
|
|
|
2019-07-19 17:17:30 +02:00
|
|
|
|
2019-07-12 10:57:03 +02:00
|
|
|
from main import * # main.py
|
2019-07-11 16:04:18 +02:00
|
|
|
|
|
|
|
# Global handler
|
|
|
|
logfile = logger.logCur
|
2019-07-09 16:13:16 +02:00
|
|
|
|
2019-07-09 23:01:09 +02:00
|
|
|
## MAIN FUNCTION OF CNIREVELATOR
|
2019-07-10 00:20:39 +02:00
|
|
|
def main():
|
2019-07-11 15:50:04 +02:00
|
|
|
logfile.printdbg('*** CNIRevelator LOGFILE. Hello World ! ***')
|
2019-07-10 10:12:54 +02:00
|
|
|
|
2019-07-12 16:12:44 +02:00
|
|
|
mainw = mainWindow()
|
2019-07-12 10:57:03 +02:00
|
|
|
|
2019-07-09 16:13:16 +02:00
|
|
|
try:
|
2019-07-11 11:16:41 +02:00
|
|
|
os.environ['PATH'] = globs.CNIRFolder + '\\Tesseract-OCR4\\'
|
|
|
|
os.environ['TESSDATA_PREFIX'] = globs.CNIRFolder + '\\Tesseract-OCR4\\tessdata'
|
2019-07-09 16:13:16 +02:00
|
|
|
tesser_version = pytesseract.get_tesseract_version()
|
|
|
|
except Exception as e:
|
2019-07-11 11:16:41 +02:00
|
|
|
logfile.printerr('ERROR WITH TESSERACT MODULE ' + str(e))
|
2019-07-09 16:13:16 +02:00
|
|
|
else:
|
|
|
|
text = 'Tesseract version ' + str(tesser_version) + ' Licensed Apache 2004 successfully initiated\n'
|
2019-07-12 10:57:03 +02:00
|
|
|
mainw.logOnTerm(text)
|
2019-07-11 11:16:41 +02:00
|
|
|
|
2019-08-12 17:07:37 +02:00
|
|
|
mainw.logOnTerm('\n\n{} \n'.format(lang.all[globs.CNIRlang]["Please type a MRZ or open a scan"]))
|
2019-07-10 10:12:54 +02:00
|
|
|
|
2019-07-11 11:16:41 +02:00
|
|
|
if globs.CNIRNewVersion:
|
2019-08-12 17:07:37 +02:00
|
|
|
showinfo("Changelog : update summary", ('{} : CNIRevelator {}\n\n{}'.format(lang.all[globs.CNIRlang]["Program version"], globs.verstring_full, globs.changelog)), parent=mainw)
|
2019-07-12 10:57:03 +02:00
|
|
|
logfile.printdbg('main() : **** Launching App_main() ****')
|
2019-08-07 15:30:22 +02:00
|
|
|
try:
|
|
|
|
mainw.mainloop()
|
|
|
|
except Exception as e:
|
2019-08-12 17:07:37 +02:00
|
|
|
showerror(lang.all[globs.CNIRlang]["CNIRevelator Fatal Error"], "{} : {}".format(lang.all[globs.CNIRlang]["An error has occured"],e), parent=mainw)
|
2019-07-12 10:57:03 +02:00
|
|
|
logfile.printdbg('main() : **** Ending App_main() ****')
|
2019-07-09 16:13:16 +02:00
|
|
|
|
2019-07-11 15:50:04 +02:00
|
|
|
logfile.printdbg('*** CNIRevelator LOGFILE. Goodbye World ! ***')
|
|
|
|
logfile.close()
|
|
|
|
|
2019-07-09 16:13:16 +02:00
|
|
|
|
2019-07-09 23:01:09 +02:00
|
|
|
## BOOTSTRAP OF CNIREVELATOR
|
2019-07-09 16:13:16 +02:00
|
|
|
|
2019-08-12 17:07:37 +02:00
|
|
|
|
|
|
|
# LANGUAGE
|
|
|
|
if os.path.isfile(globs.CNIRLangFile):
|
|
|
|
with open(globs.CNIRLangFile, 'r') as (configFile):
|
|
|
|
try:
|
|
|
|
# Reading it
|
|
|
|
globs.CNIRlang = configFile.read()
|
|
|
|
except Exception as e:
|
|
|
|
ihm.crashCNIR()
|
|
|
|
raise IOError(str(e))
|
|
|
|
else:
|
|
|
|
with open(globs.CNIRLangFile, 'w') as (configFile):
|
|
|
|
try:
|
|
|
|
# Writing it
|
|
|
|
configFile.write(globs.CNIRlang)
|
|
|
|
except Exception as e:
|
|
|
|
ihm.crashCNIR()
|
|
|
|
raise IOError(str(e))
|
|
|
|
|
|
|
|
# GO
|
2019-07-09 16:13:16 +02:00
|
|
|
try:
|
2019-07-09 23:01:09 +02:00
|
|
|
launcherThread = threading.Thread(target=updater.umain, daemon=False)
|
|
|
|
launcher.lmain(launcherThread)
|
|
|
|
except Exception:
|
2019-08-12 17:07:37 +02:00
|
|
|
ihm.crashCNIR()
|
2019-07-11 16:04:18 +02:00
|
|
|
updater.exitProcess(1)
|
2019-07-09 16:13:16 +02:00
|
|
|
|
2019-07-10 11:47:54 +02:00
|
|
|
if updater.UPDATE_IS_MADE:
|
2019-07-10 16:50:40 +02:00
|
|
|
# Launch app !
|
2019-08-12 17:07:37 +02:00
|
|
|
args = updater.UPATH + '\\CNIRevelator.exe' + " DELETE " + globs.CNIRFolder
|
2019-07-10 16:50:40 +02:00
|
|
|
cd = updater.UPATH
|
|
|
|
for i in range(0,3):
|
|
|
|
try:
|
|
|
|
updater.spawnProcess(args, cd)
|
|
|
|
except:
|
|
|
|
time.sleep(3)
|
|
|
|
continue
|
|
|
|
break
|
2019-07-11 16:04:18 +02:00
|
|
|
updater.exitProcess(0)
|
2019-07-10 11:47:54 +02:00
|
|
|
|
2019-07-11 11:16:41 +02:00
|
|
|
# Here we go !
|
|
|
|
try:
|
|
|
|
main()
|
2019-07-12 10:57:03 +02:00
|
|
|
except Exception as e:
|
2019-08-12 17:07:37 +02:00
|
|
|
ihm.crashCNIR()
|
2019-07-12 16:12:44 +02:00
|
|
|
|
|
|
|
updater.exitProcess(0)
|