refactor: unify preset loading methods in config

This commit is contained in:
Manuel Schmid 2024-03-15 21:40:35 +01:00
parent 3756d61da0
commit b2a34d2215
No known key found for this signature in database
GPG Key ID: 32C4F7569B40B84B

View File

@ -128,22 +128,6 @@ def try_get_preset_content(preset):
print(e)
return {}
def try_load_preset_global(preset):
global config_dict
if isinstance(preset, str):
preset_path = os.path.abspath(f'./presets/{preset}.json')
try:
if os.path.exists(preset_path):
with open(preset_path, "r", encoding="utf-8") as json_file:
config_dict.update(json.load(json_file))
print(f'Loaded preset: {preset_path}')
else:
raise FileNotFoundError
except Exception as e:
print(f'Load preset [{preset_path}] failed')
print(e)
try:
with open(os.path.abspath(f'./presets/default.json'), "r", encoding="utf-8") as json_file:
config_dict.update(json.load(json_file))
@ -152,7 +136,7 @@ except Exception as e:
print(e)
preset = args_manager.args.preset
try_load_preset_global(preset)
config_dict.update(try_get_preset_content(preset))
def get_path_output() -> str:
"""