From d7a801e14848ce19551a3a90c9cc5f2243c2e838 Mon Sep 17 00:00:00 2001 From: renanllisboa Date: Mon, 25 Nov 2024 16:54:05 -0300 Subject: [PATCH] add configloader loading check and some changes to restructured restart method. --- tir/technologies/core/base_database.py | 2 +- tir/technologies/core/config.py | 26 ++++++++++++++++++-------- tir/technologies/poui_internal.py | 5 ++--- tir/technologies/webapp_internal.py | 9 ++++----- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/tir/technologies/core/base_database.py b/tir/technologies/core/base_database.py index cb7f87afc..446b1da1a 100644 --- a/tir/technologies/core/base_database.py +++ b/tir/technologies/core/base_database.py @@ -80,7 +80,7 @@ def check_pyodbc_drivers(self, driver_database): filter(lambda x: x == driver_database.lower(), list(map(lambda x: x.lower(), pyodbc.drivers()))))), None): error_message = f"Driver: '{driver_database}' isn't a valid driver name!" - self.webapp_internal.restart_counter = 3 + self.webapp_internal.restart_counter += 1 self.webapp_internal.log_error(error_message) def query_execute(self, query, database_driver, dbq_oracle_server, database_server, database_port, database_name, database_user, database_password): diff --git a/tir/technologies/core/config.py b/tir/technologies/core/config.py index 52ee81f2d..4e27942de 100644 --- a/tir/technologies/core/config.py +++ b/tir/technologies/core/config.py @@ -8,9 +8,16 @@ class ConfigLoader: This class is instantiated to contain all config information used throughout the execution of the methods. """ + _instance = None _json_data = None - def __init__(self, path="config.json"): + def __new__(cls, path="config.json"): + if cls._instance is None: + cls._instance = super(ConfigLoader, cls).__new__(cls) + cls._instance._initialize(path) + return cls._instance + + def _initialize(self, path="config.json"): if ConfigLoader._json_data is None: if not path: @@ -29,6 +36,8 @@ def __init__(self, path="config.json"): raise Exception(f"JSON file issue: {e}. \n* Please check your config.json *") if ConfigLoader._json_data: + for key, value in ConfigLoader._json_data.items(): + setattr(self, key, value) data = ConfigLoader._json_data @@ -61,13 +70,6 @@ def __init__(self, path="config.json"): self.skip_restart = ("SkipRestart" in data and bool(data["SkipRestart"])) self.smart_test = ("SmartTest" in data and bool(data["SmartTest"])) self.smart_erp = ("SmartERP" in data and bool(data["SmartERP"])) - self.valid_language = self.language != "" - self.initial_program = "" - self.routine = "" - self.date = "" - self.group = "" - self.branch = "" - self.module = "" self.user_cfg = str(data["UserCfg"]) if "UserCfg" in data else "" self.password_cfg = str(data["PasswordCfg"]) if "PasswordCfg" in data else "" self.electron_binary_path = (str(data["BinPath"]) if "BinPath" in data else "") @@ -104,6 +106,14 @@ def __init__(self, path="config.json"): "SSLChromeInstallDisable" in data and bool(data["SSLChromeInstallDisable"])) self.data_delimiter = str(data["DataDelimiter"]) if "DataDelimiter" in data else "/" self.procedure_menu = str(data["ProcedureMenu"]) if "ProcedureMenu" in data else "" + self.valid_language = self.language != "" + self.initial_program = "" + self.routine = "" + self.date = "" + self.group = "" + self.branch = "" + self.module = "" + self.routine_type = "" def check_keys(self, json_data): valid_keys = [ diff --git a/tir/technologies/poui_internal.py b/tir/technologies/poui_internal.py index 05e07b0ea..3b02b7828 100644 --- a/tir/technologies/poui_internal.py +++ b/tir/technologies/poui_internal.py @@ -93,7 +93,6 @@ def __init__(self, config_path="", autostart=True): self.tmenu_screen = None self.grid_memo_field = False self.range_multiplier = None - self.routine = None if not Base.driver: Base.driver = self.driver @@ -1289,9 +1288,9 @@ def restart(self): if self.config.routine: - if self.routine == 'SetLateralMenu': + if self.config.routine_type.lower() == 'setlateralmenu': self.SetLateralMenu(self.config.routine, save_input=False) - elif self.routine == 'Program': + elif self.config.routine_type.lower() == 'program': self.set_program(self.config.routine) def driver_refresh(self): diff --git a/tir/technologies/webapp_internal.py b/tir/technologies/webapp_internal.py index 0be472aeb..89c6dacdd 100644 --- a/tir/technologies/webapp_internal.py +++ b/tir/technologies/webapp_internal.py @@ -104,7 +104,6 @@ def __init__(self, config_path="", autostart=True): self.tmenu_screen = None self.grid_memo_field = False self.range_multiplier = None - self.routine = None self.test_suite = [] self.current_test_suite = self.log.get_file_name('testsuite') self.restart_tss = False @@ -1561,7 +1560,7 @@ def Program(self, program_name): >>> # Calling the method: >>> oHelper.Program("MATA020") """ - self.routine = 'Program' + self.config.routine_type = 'Program' self.config.routine = program_name if self.config.log_info_config: @@ -3274,9 +3273,9 @@ def restart(self): if self.config.routine: - if self.routine == 'SetLateralMenu': + if self.config.routine_type == 'SetLateralMenu': self.SetLateralMenu(self.config.routine, save_input=False) - elif self.routine == 'Program': + elif self.config.routine_type == 'Program': self.set_program(self.config.routine) def wait_user_screen(self): @@ -3964,7 +3963,7 @@ def SetLateralMenu(self, menu_itens, save_input=True, click_menu_functional=Fals self.log_error_newlog() if save_input: - self.routine = 'SetLateralMenu' + self.config.routine_type = 'SetLateralMenu' self.config.routine = menu_itens if self.webapp_shadowroot():