From 30e1b15dd18fdf81c2c62d5a7bcb60f34d801fa4 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 26 Aug 2019 16:50:51 +0200 Subject: [PATCH] Added temporization on update to prevent updating every launch --- src/globs.py | 17 +--------------- src/updater.py | 55 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/globs.py b/src/globs.py index e960336..bb8f289 100644 --- a/src/globs.py +++ b/src/globs.py @@ -31,22 +31,6 @@ version = [3, 1, 4] verstring_full = "{}.{}.{} {}".format(version[0], version[1], version[2], verType) verstring = "{}.{}".format(version[0], version[1]) -CNIRTesserHash = '5b58db27f7bc08c58a2cb33d01533b034b067cf8' -CNIRFolder = os.getcwd() -CNIRLColor = "#006699" -CNIRName = "CNIRevelator {}".format(verstring) -CNIRCryptoKey = '82Xh!efX3#@P~2eG' -CNIRNewVersion = False - -CNIRConfig = CNIRFolder + '\\config\\conf.ig' -CNIRTesser = CNIRFolder + '\\Tesseract-OCR5\\' -CNIRErrLog = CNIRFolder + '\\logs\\error.log' -CNIRMainLog = CNIRFolder + '\\logs\\main.log' -CNIRUrlConfig = CNIRFolder + '\\config\\urlconf.ig' -CNIRVerStock = CNIRFolder + '\\downloads\\versions.lst' -CNIREnv = CNIRFolder + '\\Data\\' - - CNIRTesserHash = '947224361ffab8c01f05c9394b44b1bd7c8c3d4d' CNIRFolder = os.path.dirname(os.path.realpath(__file__)) CNIRLColor = "#006699" @@ -61,6 +45,7 @@ CNIRTesser = CNIRFolder + '\\Tesseract-OCR5\\' CNIRErrLog = CNIRFolder + '\\logs\\error.log' CNIRMainLog = CNIRFolder + '\\logs\\main.log' CNIRUrlConfig = CNIRFolder + '\\config\\urlconf.ig' +CNIRLastUpdate = CNIRFolder + '\\config\\lastupdate.ig' CNIRVerStock = CNIRFolder + '\\downloads\\versions.lst' CNIREnv = CNIRFolder + '\\Data\\' diff --git a/src/updater.py b/src/updater.py index e8ef15d..ac30b06 100644 --- a/src/updater.py +++ b/src/updater.py @@ -36,6 +36,7 @@ import zipfile import hashlib import subprocess import psutil +import datetime import critical # critical.py import github # github.py @@ -316,17 +317,6 @@ def umain(): # Global Handlers logfile = logger.logCur - - credentials = downloader.newcredentials() - - if not credentials.valid: - logfile.printerr("Credentials Error. No effective update !") - launcherWindow.printmsg(lang.all[globs.CNIRlang]["Credentials Error. No effective update !"]) - time.sleep(2) - launcherWindow.exit() - return 0 - - github.credentials = credentials # Cleaner for the old version if detected if len(sys.argv) > 2 and str(sys.argv[1]) == "DELETE": @@ -361,6 +351,49 @@ def umain(): globs.CNIROpenFile = True logfile.printdbg("Command line received : {}".format(sys.argv)) + credentials = downloader.newcredentials() + + if not credentials.valid: + logfile.printerr("Credentials Error. No effective update !") + launcherWindow.printmsg(lang.all[globs.CNIRlang]["Credentials Error. No effective update !"]) + time.sleep(2) + launcherWindow.exit() + return 0 + + github.credentials = credentials + + # Check if update is needed + currentDate = datetime.datetime.now() + + if os.path.isfile(globs.CNIRLastUpdate): + with open(globs.CNIRLastUpdate, 'r') as (configFile): + try: + # Reading it + lastUpdate = datetime.datetime.strptime(configFile.read(),"%d/%m/%Y") + except Exception as e: + critical.crashCNIR() + raise IOError(str(e)) + else: + # Recreating the url file + lastUpdate = currentDate + try: + os.mkdir(globs.CNIRFolder + '\\config') + except: + pass + + with open(globs.CNIRLastUpdate, 'w') as (configFile): + try: + # Writing it + configFile.write("{}/{}/{}".format(currentDate.day, currentDate.month, currentDate.year)) + except Exception as e: + critical.crashCNIR() + raise IOError(str(e)) + + if (currentDate - lastUpdate).min !=0 and (currentDate - lastUpdate).days < 7: + launcherWindow.exit() + return 0 + + # Update batch try: try: # EXECUTING THE UPDATE BATCH