Minor corrections and hotfixes

This commit is contained in:
Adrien Bourmault 2019-08-05 15:52:02 +02:00 committed by GitHub
parent bd63875eed
commit 722354d6e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 26 deletions

View File

@ -157,15 +157,16 @@ class newcredentials:
return
class newdownload:
def __init__(self, credentials, urlFile, destinationFile):
def __init__(self, credentials, urlFile, destinationFile, title):
self.urlFile = urlFile
self.destinationFile = destinationFile
self.session = credentials.sessionHandler
self.title = title
logfile = logger.logCur
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.raise_for_status()
@ -179,10 +180,12 @@ class newdownload:
launcherWindow = ihm.launcherWindowCur
url = self.urlFile
filename = self.destinationFile
title = self.title
reducedFilename = filename.split("\\")[-1]
launcherWindow.printmsg('Downloading {}'.format(reducedFilename))
launcherWindow.printmsg('Downloading {}'.format(title))
logfile.printdbg('Requesting download of {}'.format(reducedFilename))
try:
os.remove(filename)
@ -198,7 +201,7 @@ class newdownload:
launcherWindow.progressBar.stop()
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.start()

View File

@ -25,8 +25,9 @@
import os
# CNIRevelator version
version = [3, 0, 1]
verstring_full = "{}.{}.{}".format(version[0], version[1], version[2])
verType = "alpha"
version = [3, 0, 2]
verstring_full = "{}.{}.{} {}".format(version[0], version[1], version[2], verType)
verstring = "{}.{}".format(version[0], version[1])
debug = True

View File

@ -32,7 +32,7 @@ import logger # logger.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):

View File

@ -61,9 +61,9 @@ class NewLoggingSystem:
self.printerr = logger.error
if globs.debug:
self.printdbg = self.logger.info(text)
self.printdbg = self.logger.info
else:
self.printdbg = self.doNothing(text)
self.printdbg = self.doNothing
def doNothing(self, text):
pass

View File

@ -267,6 +267,8 @@ class mainWindow(Tk):
self.logOnTerm("Document detecté : {}\n".format(candidates[0][2]))
self.mrzDecided = candidates[0]
else:
# get the cursor position
curPos = self.termtext.index(INSERT)
# break the line
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
@ -274,6 +276,7 @@ class mainWindow(Tk):
self.mrzChar = self.termtext.get("1.0", "end")[:-1]
self.termtext.delete("1.0","end")
self.termtext.insert("1.0", self.mrzChar[:-1])
self.termtext.mark_set(INSERT, curPos)
else:
# In case of there is a second line
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.termtext.delete("1.0","end")
self.termtext.insert("1.0", self.mrzChar[:-1])
self.termtext.mark_set(INSERT, curPos)
# compute the control sum if needed
self.computeSigma()
@ -328,6 +332,27 @@ class mainWindow(Tk):
self.termtext.mark_set("insert", "%d.%d" % (int(position[0]), int(position[1]) + number))
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 controlled and not event.keysym in ihm.controlKeys:
@ -434,8 +459,19 @@ class mainWindow(Tk):
Tk().withdraw()
showinfo('Aide sur les contrôles au clavier',
( '' + '\n\n' +
"In construction"
( "Terminal de saisie rapide (731) : \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"
" 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)
@ -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]))
# if sum is facultative or if sum is ok
if sum[3] or int(code[sum[1]]) == int(sum[2]):
self.termtext.tag_add("conforme", "{}.{}".format(x,y), "{}.{}".format(x,y+1))
self.termtext.tag_configure("conforme", background="green", foreground="white")
else:
try:
if sum[3] or int(code[sum[1]]) == int(sum[2]):
self.termtext.tag_add("conforme", "{}.{}".format(x,y), "{}.{}".format(x,y+1))
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_configure("nonconforme", background="red", relief='raised', foreground="white")
self.compliance = False
if self.compliance == True:
self.STATUStxt['text'] = 'CONFORME'
self.STATUStxt['fg'] = "green"

View File

@ -120,8 +120,8 @@ def getLatestVersion(credentials):
os.mkdir(globs.CNIRFolder + '\\downloads')
except:
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')
with open(globs.CNIRVerStock) as versionsFile:
versionsTab = versionsFile.read().split("\n")[1].split("||")
@ -130,7 +130,7 @@ def getLatestVersion(credentials):
finalver = globs.version.copy()
for entry in versionsTab:
if not entry:
break
continue
verstr, url, checksum = entry.split("|")
# Calculating sum considering we can have 99 sub versions
ver = verstr.split(".")
@ -142,6 +142,9 @@ def getLatestVersion(credentials):
finalver = ver.copy()
finalurl = url
finalchecksum = checksum
else:
finalurl = None
finalchecksum = None
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
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
logfile.printdbg("Unzipping the package")
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.close()
# Cleanup
try:
os.remove(UPATH + '\\TsrtPackage.zip')
os.remove(UPATH + '\\downloads\\TsrtPackage.zip')
except:
pass
@ -189,7 +192,7 @@ def batch(credentials):
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...')
@ -198,7 +201,7 @@ def batch(credentials):
sha1 = hashlib.sha1()
with open(globs.CNIRFolder + '\\..\\CNIPackage.zip', 'rb') as f:
with open(globs.CNIRFolder + '\\downloads\\CNIPackage.zip', 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
@ -229,7 +232,7 @@ def batch(credentials):
# Unzip
logfile.printdbg("Unzipping the package")
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.close()
@ -245,7 +248,7 @@ def batch(credentials):
# Cleanup
try:
os.remove(globs.CNIRFolder + '\\..\\CNIPackage.zip')
os.remove(globs.CNIRFolder + '\\downloads\\CNIPackage.zip')
except:
pass
# Time to quit