mirror of
https://gitlab.os-k.eu/neox/CNIRevelator.git
synced 2023-08-25 14:03:10 +02:00
Minor corrections and hotfixes
This commit is contained in:
parent
bd63875eed
commit
722354d6e4
@ -157,15 +157,16 @@ class newcredentials:
|
|||||||
return
|
return
|
||||||
|
|
||||||
class newdownload:
|
class newdownload:
|
||||||
def __init__(self, credentials, urlFile, destinationFile):
|
def __init__(self, credentials, urlFile, destinationFile, title):
|
||||||
self.urlFile = urlFile
|
self.urlFile = urlFile
|
||||||
self.destinationFile = destinationFile
|
self.destinationFile = destinationFile
|
||||||
self.session = credentials.sessionHandler
|
self.session = credentials.sessionHandler
|
||||||
|
self.title = title
|
||||||
|
|
||||||
logfile = logger.logCur
|
logfile = logger.logCur
|
||||||
launcherWindow = ihm.launcherWindowCur
|
launcherWindow = ihm.launcherWindowCur
|
||||||
|
|
||||||
logfile.printdbg('Requesting download of {}'.format(self.urlFile))
|
logfile.printdbg('Requesting download of {}'.format(urlFile))
|
||||||
|
|
||||||
self.handler = self.session.get(self.urlFile, stream=True, headers={'Connection' : 'close', "Cache-Control": "no-cache", "Pragma": "no-cache"})
|
self.handler = self.session.get(self.urlFile, stream=True, headers={'Connection' : 'close', "Cache-Control": "no-cache", "Pragma": "no-cache"})
|
||||||
self.handler.raise_for_status()
|
self.handler.raise_for_status()
|
||||||
@ -179,10 +180,12 @@ class newdownload:
|
|||||||
launcherWindow = ihm.launcherWindowCur
|
launcherWindow = ihm.launcherWindowCur
|
||||||
url = self.urlFile
|
url = self.urlFile
|
||||||
filename = self.destinationFile
|
filename = self.destinationFile
|
||||||
|
title = self.title
|
||||||
|
|
||||||
reducedFilename = filename.split("\\")[-1]
|
reducedFilename = filename.split("\\")[-1]
|
||||||
|
|
||||||
launcherWindow.printmsg('Downloading {}'.format(reducedFilename))
|
launcherWindow.printmsg('Downloading {}'.format(title))
|
||||||
|
logfile.printdbg('Requesting download of {}'.format(reducedFilename))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
@ -198,7 +201,7 @@ class newdownload:
|
|||||||
|
|
||||||
launcherWindow.progressBar.stop()
|
launcherWindow.progressBar.stop()
|
||||||
launcherWindow.progressBar.configure(mode='determinate', value=(int(Percent)), maximum=100)
|
launcherWindow.progressBar.configure(mode='determinate', value=(int(Percent)), maximum=100)
|
||||||
launcherWindow.printmsg('Downloading {}'.format(reducedFilename) + ' : {:4.2f} %'.format(Percent))
|
launcherWindow.printmsg('Downloading {}'.format(title) + ' : {:4.2f} %'.format(Percent))
|
||||||
|
|
||||||
launcherWindow.progressBar.configure(mode='indeterminate', value=0, maximum=20)
|
launcherWindow.progressBar.configure(mode='indeterminate', value=0, maximum=20)
|
||||||
launcherWindow.progressBar.start()
|
launcherWindow.progressBar.start()
|
||||||
|
@ -25,8 +25,9 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# CNIRevelator version
|
# CNIRevelator version
|
||||||
version = [3, 0, 1]
|
verType = "alpha"
|
||||||
verstring_full = "{}.{}.{}".format(version[0], version[1], version[2])
|
version = [3, 0, 2]
|
||||||
|
verstring_full = "{}.{}.{} {}".format(version[0], version[1], version[2], verType)
|
||||||
verstring = "{}.{}".format(version[0], version[1])
|
verstring = "{}.{}".format(version[0], version[1])
|
||||||
debug = True
|
debug = True
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ import logger # logger.py
|
|||||||
import globs # globs.py
|
import globs # globs.py
|
||||||
|
|
||||||
|
|
||||||
controlKeys = ["Right", "Left", "Up", "Down", "Home", "End", "Delete", "Inser", "Shift_L", "Shift_R", "Control_R", "Control_L"]
|
controlKeys = ["Escape", "Right", "Left", "Up", "Down", "Home", "End", "BackSpace", "Delete", "Inser", "Shift_L", "Shift_R", "Control_R", "Control_L"]
|
||||||
|
|
||||||
class DocumentAsk(Toplevel):
|
class DocumentAsk(Toplevel):
|
||||||
|
|
||||||
|
@ -61,9 +61,9 @@ class NewLoggingSystem:
|
|||||||
self.printerr = logger.error
|
self.printerr = logger.error
|
||||||
|
|
||||||
if globs.debug:
|
if globs.debug:
|
||||||
self.printdbg = self.logger.info(text)
|
self.printdbg = self.logger.info
|
||||||
else:
|
else:
|
||||||
self.printdbg = self.doNothing(text)
|
self.printdbg = self.doNothing
|
||||||
|
|
||||||
def doNothing(self, text):
|
def doNothing(self, text):
|
||||||
pass
|
pass
|
||||||
|
54
src/main.py
54
src/main.py
@ -267,6 +267,8 @@ class mainWindow(Tk):
|
|||||||
self.logOnTerm("Document detecté : {}\n".format(candidates[0][2]))
|
self.logOnTerm("Document detecté : {}\n".format(candidates[0][2]))
|
||||||
self.mrzDecided = candidates[0]
|
self.mrzDecided = candidates[0]
|
||||||
else:
|
else:
|
||||||
|
# get the cursor position
|
||||||
|
curPos = self.termtext.index(INSERT)
|
||||||
# break the line
|
# break the line
|
||||||
if (len(self.mrzChar) - 2 >= len(self.mrzDecided[0][0])) and ("\n" not in self.mrzChar[:-1]):
|
if (len(self.mrzChar) - 2 >= len(self.mrzDecided[0][0])) and ("\n" not in self.mrzChar[:-1]):
|
||||||
# In case of there is no second line
|
# In case of there is no second line
|
||||||
@ -274,6 +276,7 @@ class mainWindow(Tk):
|
|||||||
self.mrzChar = self.termtext.get("1.0", "end")[:-1]
|
self.mrzChar = self.termtext.get("1.0", "end")[:-1]
|
||||||
self.termtext.delete("1.0","end")
|
self.termtext.delete("1.0","end")
|
||||||
self.termtext.insert("1.0", self.mrzChar[:-1])
|
self.termtext.insert("1.0", self.mrzChar[:-1])
|
||||||
|
self.termtext.mark_set(INSERT, curPos)
|
||||||
else:
|
else:
|
||||||
# In case of there is a second line
|
# In case of there is a second line
|
||||||
self.mrzChar = self.termtext.get("1.0", "end")[:-1] + '\n'
|
self.mrzChar = self.termtext.get("1.0", "end")[:-1] + '\n'
|
||||||
@ -284,6 +287,7 @@ class mainWindow(Tk):
|
|||||||
self.mrzChar = self.termtext.get("1.0", "end")[:-1]
|
self.mrzChar = self.termtext.get("1.0", "end")[:-1]
|
||||||
self.termtext.delete("1.0","end")
|
self.termtext.delete("1.0","end")
|
||||||
self.termtext.insert("1.0", self.mrzChar[:-1])
|
self.termtext.insert("1.0", self.mrzChar[:-1])
|
||||||
|
self.termtext.mark_set(INSERT, curPos)
|
||||||
# compute the control sum if needed
|
# compute the control sum if needed
|
||||||
self.computeSigma()
|
self.computeSigma()
|
||||||
|
|
||||||
@ -328,6 +332,27 @@ class mainWindow(Tk):
|
|||||||
self.termtext.mark_set("insert", "%d.%d" % (int(position[0]), int(position[1]) + number))
|
self.termtext.mark_set("insert", "%d.%d" % (int(position[0]), int(position[1]) + number))
|
||||||
return "break"
|
return "break"
|
||||||
|
|
||||||
|
if event.keysym == "Escape":
|
||||||
|
if self.mrzDecided:
|
||||||
|
# Get the candidates
|
||||||
|
candidates = mrz.allDocMatch(self.mrzChar.split("\n"))
|
||||||
|
|
||||||
|
if len(candidates) == 2 and len(self.mrzChar) >= 8:
|
||||||
|
# Parameters for the choice invite
|
||||||
|
invite = ihm.DocumentAsk(self, [candidates[0][2], candidates[1][2]])
|
||||||
|
invite.transient(self)
|
||||||
|
invite.grab_set()
|
||||||
|
invite.focus_force()
|
||||||
|
|
||||||
|
self.wait_window(invite)
|
||||||
|
|
||||||
|
self.logOnTerm("Document re-detecté : {}\n".format(candidates[invite.choice][2]))
|
||||||
|
self.mrzDecided = candidates[invite.choice]
|
||||||
|
|
||||||
|
elif len(candidates) == 1:
|
||||||
|
self.logOnTerm("Document re-detecté : {}\n".format(candidates[0][2]))
|
||||||
|
self.mrzDecided = candidates[0]
|
||||||
|
return "break"
|
||||||
|
|
||||||
# If not a control char
|
# If not a control char
|
||||||
if not controlled and not event.keysym in ihm.controlKeys:
|
if not controlled and not event.keysym in ihm.controlKeys:
|
||||||
@ -434,8 +459,19 @@ class mainWindow(Tk):
|
|||||||
Tk().withdraw()
|
Tk().withdraw()
|
||||||
|
|
||||||
showinfo('Aide sur les contrôles au clavier',
|
showinfo('Aide sur les contrôles au clavier',
|
||||||
( '' + '\n\n' +
|
( "Terminal de saisie rapide (731) : \n\n"
|
||||||
"In construction"
|
" Caractères autorisés : Alphanumériques en majuscule et le caractère '<'. Pas de minuscules ni caractères spéciaux, autrement la somme est mise à zéro \n\n"
|
||||||
|
" Calculer résultat :\t\t\tTouche Ctrl droite \n"
|
||||||
|
" Copier :\t\t\t\tCtrl-C \n"
|
||||||
|
" Coller :\t\t\t\tCtrl-V \n"
|
||||||
|
"\n\n"
|
||||||
|
"Terminal de saisie MRZ complète : \n\n"
|
||||||
|
" Caractères autorisés : Alphanumériques en majuscule et le caractère '<'. Pas de minuscules ni caractères spéciaux, autrement la somme est mise à zéro \n\n"
|
||||||
|
" Calculer résultat :\t\t\tTouche Ctrl droite \n"
|
||||||
|
" Compléter champ :\t\t\tTouche Tab \n"
|
||||||
|
" Copier :\t\t\t\tCtrl-C \n"
|
||||||
|
" Coller :\t\t\t\tCtrl-V \n"
|
||||||
|
" Forcer une nouvelle détection du document :\tEchap\n"
|
||||||
),
|
),
|
||||||
|
|
||||||
parent=self)
|
parent=self)
|
||||||
@ -467,15 +503,19 @@ class mainWindow(Tk):
|
|||||||
self.logOnTerm("Somme de contrôle position {} : Lu {} VS Calculé {}\n".format(sum[1], code[sum[1]], sum[2]))
|
self.logOnTerm("Somme de contrôle position {} : Lu {} VS Calculé {}\n".format(sum[1], code[sum[1]], sum[2]))
|
||||||
|
|
||||||
# if sum is facultative or if sum is ok
|
# if sum is facultative or if sum is ok
|
||||||
if sum[3] or int(code[sum[1]]) == int(sum[2]):
|
try:
|
||||||
self.termtext.tag_add("conforme", "{}.{}".format(x,y), "{}.{}".format(x,y+1))
|
if sum[3] or int(code[sum[1]]) == int(sum[2]):
|
||||||
self.termtext.tag_configure("conforme", background="green", foreground="white")
|
self.termtext.tag_add("conforme", "{}.{}".format(x,y), "{}.{}".format(x,y+1))
|
||||||
else:
|
self.termtext.tag_configure("conforme", background="green", foreground="white")
|
||||||
|
else:
|
||||||
|
self.termtext.tag_add("nonconforme", "{}.{}".format(x,y), "{}.{}".format(x,y+1))
|
||||||
|
self.termtext.tag_configure("nonconforme", background="red", relief='raised', foreground="white")
|
||||||
|
self.compliance = False
|
||||||
|
except ValueError:
|
||||||
self.termtext.tag_add("nonconforme", "{}.{}".format(x,y), "{}.{}".format(x,y+1))
|
self.termtext.tag_add("nonconforme", "{}.{}".format(x,y), "{}.{}".format(x,y+1))
|
||||||
self.termtext.tag_configure("nonconforme", background="red", relief='raised', foreground="white")
|
self.termtext.tag_configure("nonconforme", background="red", relief='raised', foreground="white")
|
||||||
self.compliance = False
|
self.compliance = False
|
||||||
|
|
||||||
|
|
||||||
if self.compliance == True:
|
if self.compliance == True:
|
||||||
self.STATUStxt['text'] = 'CONFORME'
|
self.STATUStxt['text'] = 'CONFORME'
|
||||||
self.STATUStxt['fg'] = "green"
|
self.STATUStxt['fg'] = "green"
|
||||||
|
@ -120,8 +120,8 @@ def getLatestVersion(credentials):
|
|||||||
os.mkdir(globs.CNIRFolder + '\\downloads')
|
os.mkdir(globs.CNIRFolder + '\\downloads')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
getTheVersions = downloader.newdownload(credentials, urlparsed[0], globs.CNIRVerStock).download()
|
getTheVersions = downloader.newdownload(credentials, urlparsed[0], globs.CNIRVerStock, "the version repository").download()
|
||||||
|
|
||||||
logfile.printdbg('Parsing the software versions')
|
logfile.printdbg('Parsing the software versions')
|
||||||
with open(globs.CNIRVerStock) as versionsFile:
|
with open(globs.CNIRVerStock) as versionsFile:
|
||||||
versionsTab = versionsFile.read().split("\n")[1].split("||")
|
versionsTab = versionsFile.read().split("\n")[1].split("||")
|
||||||
@ -130,7 +130,7 @@ def getLatestVersion(credentials):
|
|||||||
finalver = globs.version.copy()
|
finalver = globs.version.copy()
|
||||||
for entry in versionsTab:
|
for entry in versionsTab:
|
||||||
if not entry:
|
if not entry:
|
||||||
break
|
continue
|
||||||
verstr, url, checksum = entry.split("|")
|
verstr, url, checksum = entry.split("|")
|
||||||
# Calculating sum considering we can have 99 sub versions
|
# Calculating sum considering we can have 99 sub versions
|
||||||
ver = verstr.split(".")
|
ver = verstr.split(".")
|
||||||
@ -142,6 +142,9 @@ def getLatestVersion(credentials):
|
|||||||
finalver = ver.copy()
|
finalver = ver.copy()
|
||||||
finalurl = url
|
finalurl = url
|
||||||
finalchecksum = checksum
|
finalchecksum = checksum
|
||||||
|
else:
|
||||||
|
finalurl = None
|
||||||
|
finalchecksum = None
|
||||||
|
|
||||||
return (finalver, finalurl, finalchecksum)
|
return (finalver, finalurl, finalchecksum)
|
||||||
|
|
||||||
@ -159,18 +162,18 @@ def tessInstall(PATH, credentials):
|
|||||||
|
|
||||||
# WE ASSUME THAT THE MAIN FILE IS CNIRevelator.zip AND THAT THE TESSERACT PACKAGE IS 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...')
|
logfile.printdbg('Preparing download of Tesseract OCR 4...')
|
||||||
getTesseract = downloader.newdownload(credentials, tesseracturl, PATH + '\\TsrtPackage.zip').download()
|
getTesseract = downloader.newdownload(credentials, tesseracturl, PATH + '\\downloads\\TsrtPackage.zip', "Tesseract 4 OCR Module").download()
|
||||||
|
|
||||||
# Unzip Tesseract
|
# Unzip Tesseract
|
||||||
logfile.printdbg("Unzipping the package")
|
logfile.printdbg("Unzipping the package")
|
||||||
launcherWindow.printmsg('Installing the updates')
|
launcherWindow.printmsg('Installing the updates')
|
||||||
zip_ref = zipfile.ZipFile(PATH + '\\TsrtPackage.zip', 'r')
|
zip_ref = zipfile.ZipFile(PATH + '\\downloads\\TsrtPackage.zip', 'r')
|
||||||
zip_ref.extractall(PATH)
|
zip_ref.extractall(PATH)
|
||||||
zip_ref.close()
|
zip_ref.close()
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
try:
|
try:
|
||||||
os.remove(UPATH + '\\TsrtPackage.zip')
|
os.remove(UPATH + '\\downloads\\TsrtPackage.zip')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -189,7 +192,7 @@ def batch(credentials):
|
|||||||
|
|
||||||
logfile.printdbg('Preparing download for the new version')
|
logfile.printdbg('Preparing download for the new version')
|
||||||
|
|
||||||
getTheUpdate = downloader.newdownload(credentials, finalurl, globs.CNIRFolder + '\\..\\CNIPackage.zip').download()
|
getTheUpdate = downloader.newdownload(credentials, finalurl, globs.CNIRFolder + '\\downloads\\CNIPackage.zip', "CNIRevelator {}.{}.{}".format(finalver[0], finalver[1], finalver[2])).download()
|
||||||
|
|
||||||
launcherWindow.printmsg('Verifying download...')
|
launcherWindow.printmsg('Verifying download...')
|
||||||
|
|
||||||
@ -198,7 +201,7 @@ def batch(credentials):
|
|||||||
|
|
||||||
sha1 = hashlib.sha1()
|
sha1 = hashlib.sha1()
|
||||||
|
|
||||||
with open(globs.CNIRFolder + '\\..\\CNIPackage.zip', 'rb') as f:
|
with open(globs.CNIRFolder + '\\downloads\\CNIPackage.zip', 'rb') as f:
|
||||||
while True:
|
while True:
|
||||||
data = f.read(BUF_SIZE)
|
data = f.read(BUF_SIZE)
|
||||||
if not data:
|
if not data:
|
||||||
@ -229,7 +232,7 @@ def batch(credentials):
|
|||||||
# Unzip
|
# Unzip
|
||||||
logfile.printdbg("Unzipping the package")
|
logfile.printdbg("Unzipping the package")
|
||||||
launcherWindow.printmsg('Installing the updates')
|
launcherWindow.printmsg('Installing the updates')
|
||||||
zip_ref = zipfile.ZipFile(globs.CNIRFolder + '\\..\\CNIPackage.zip', 'r')
|
zip_ref = zipfile.ZipFile(globs.CNIRFolder + '\\downloads\\CNIPackage.zip', 'r')
|
||||||
zip_ref.extractall(UPATH + "temp")
|
zip_ref.extractall(UPATH + "temp")
|
||||||
zip_ref.close()
|
zip_ref.close()
|
||||||
|
|
||||||
@ -245,7 +248,7 @@ def batch(credentials):
|
|||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
try:
|
try:
|
||||||
os.remove(globs.CNIRFolder + '\\..\\CNIPackage.zip')
|
os.remove(globs.CNIRFolder + '\\downloads\\CNIPackage.zip')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# Time to quit
|
# Time to quit
|
||||||
|
Loading…
Reference in New Issue
Block a user