From 3cd2077f63b53c1152743b9611e4eebee46e21a4 Mon Sep 17 00:00:00 2001 From: adator <85586985+adator85@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:08:08 +0200 Subject: [PATCH] update installation module --- core/installation.py | 43 ++++++++++++++++++++++--------------------- core/loadConf.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/core/installation.py b/core/installation.py index 9245968..2cdd5c4 100644 --- a/core/installation.py +++ b/core/installation.py @@ -28,22 +28,17 @@ class Install: self.set_configuration() - if not self.check_python_version(): - # Tester si c'est la bonne version de python - exit("Python Version Error") - else: + if self.skip_install: + return None - if self.skip_install: - return None + # Sinon tester les dependances python et les installer avec pip + if self.do_install(): - # Sinon tester les dependances python et les installer avec pip - if self.do_install(): + self.install_dependencies() - self.install_dependencies() + self.create_service_file() - self.create_service_file() - - self.print_final_message() + self.print_final_message() return None @@ -74,18 +69,24 @@ class Install: venv_python_executable=f'{os.path.join(defender_install_folder, venv_folder, "bin")}{os.sep}python' ) - # Exclude Windows OS + if self.check_python_version(): + # If the Python version is not good then Exit + exit("/!\\ Python version error /!\\") + + if not os.path.exists(os.path.join(self.config.defender_install_folder, 'core', 'configuration.json')): + # If configuration file do not exist + exit("/!\\ Configuration file (configuration.json) doesn't exist /!\\") + + # Exclude Windows OS from the installation if os.name == 'nt': #print('/!\\ Skip installation /!\\') self.skip_install = True - else: - if self.is_root(): - print(f'/!\\ I fully not recommend running Defender as root /!\\') - self.skip_install = True - # Check if configuration.json exist - if not os.path.exists({os.path.join(self.config.defender_install_folder, 'core', 'configuration.json')}): - print(f'/!\\ configuration.json is not available, please create it first /!\\') - self.skip_install = True + return False + + if self.is_root(): + exit(f'/!\\ I highly not recommend running Defender as root /!\\') + self.skip_install = True + return False def is_root(self) -> bool: diff --git a/core/loadConf.py b/core/loadConf.py index 80dc404..8735ddc 100644 --- a/core/loadConf.py +++ b/core/loadConf.py @@ -150,8 +150,33 @@ class Config: with open(conf_filename, 'r') as configuration_data: configuration:dict[str, Union[str, int, list, dict]] = json.load(configuration_data) - for key, value in configuration['CONFIG_COLOR'].items(): - configuration['CONFIG_COLOR'][key] = str(value).encode('utf-8').decode('unicode_escape') + config_dict = {"CONFIG_COLOR" : { + "blanche": "\\u0003\\u0030", + "noire": "\\u0003\\u0031", + "bleue": "\\u0003\\u0020", + "verte": "\\u0003\\u0033", + "rouge": "\\u0003\\u0034", + "jaune": "\\u0003\\u0036", + "gras": "\\u0002", + "nogc": "\\u0002\\u0003" + } + } + + missing_color = False + + if not "CONFIG_COLOR" in configuration: + missing_color = True + configuration_color = config_dict + else: + configuration_color = configuration["CONFIG_COLOR"] + + if missing_color: + for key, value in configuration_color.items(): + configuration_color['CONFIG_COLOR'][key] = str(value).encode('utf-8').decode('unicode_escape') + configuration['CONFIG_COLOR'] = configuration_color['CONFIG_COLOR'] + else: + for key, value in configuration['CONFIG_COLOR'].items(): + configuration['CONFIG_COLOR'][key] = str(value).encode('utf-8').decode('unicode_escape') return configuration