update installation module

This commit is contained in:
adator
2024-09-18 19:08:08 +02:00
parent 9c78ad0860
commit 3cd2077f63
2 changed files with 49 additions and 23 deletions

View File

@@ -28,22 +28,17 @@ class Install:
self.set_configuration() self.set_configuration()
if not self.check_python_version(): if self.skip_install:
# Tester si c'est la bonne version de python return None
exit("Python Version Error")
else:
if self.skip_install: # Sinon tester les dependances python et les installer avec pip
return None if self.do_install():
# Sinon tester les dependances python et les installer avec pip self.install_dependencies()
if self.do_install():
self.install_dependencies() self.create_service_file()
self.create_service_file() self.print_final_message()
self.print_final_message()
return None return None
@@ -74,18 +69,24 @@ class Install:
venv_python_executable=f'{os.path.join(defender_install_folder, venv_folder, "bin")}{os.sep}python' 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': if os.name == 'nt':
#print('/!\\ Skip installation /!\\') #print('/!\\ Skip installation /!\\')
self.skip_install = True self.skip_install = True
else: return False
if self.is_root():
print(f'/!\\ I fully not recommend running Defender as root /!\\') if self.is_root():
self.skip_install = True exit(f'/!\\ I highly not recommend running Defender as root /!\\')
# Check if configuration.json exist self.skip_install = True
if not os.path.exists({os.path.join(self.config.defender_install_folder, 'core', 'configuration.json')}): return False
print(f'/!\\ configuration.json is not available, please create it first /!\\')
self.skip_install = True
def is_root(self) -> bool: def is_root(self) -> bool:

View File

@@ -150,8 +150,33 @@ class Config:
with open(conf_filename, 'r') as configuration_data: with open(conf_filename, 'r') as configuration_data:
configuration:dict[str, Union[str, int, list, dict]] = json.load(configuration_data) configuration:dict[str, Union[str, int, list, dict]] = json.load(configuration_data)
for key, value in configuration['CONFIG_COLOR'].items(): config_dict = {"CONFIG_COLOR" : {
configuration['CONFIG_COLOR'][key] = str(value).encode('utf-8').decode('unicode_escape') "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 return configuration