Allow settings block to not exist via call setting

This commit is contained in:
Clemens Schwaighofer
2025-07-14 18:14:33 +09:00
parent b74ed1f30e
commit 99bca2c467

View File

@@ -66,7 +66,12 @@ class SettingsLoader:
self._check_settings_abort: bool = False
# MARK: load settings
def load_settings(self, config_id: str, config_validate: dict[str, list[str]]) -> dict[str, str]:
def load_settings(
self,
config_id: str,
config_validate: dict[str, list[str]],
allow_not_exist: bool = False
) -> dict[str, str]:
"""
neutral settings loader
@@ -86,7 +91,8 @@ class SettingsLoader:
Args:
config_id (str): what block to load
config_allowed (list[str]): list of allowed entries sets
config_validate (dict[str, list[str]]): list of allowed entries sets
allow_not_exist (bool): If set to True, does not throw an error, but returns empty set
Returns:
dict[str, str]: key = value list
@@ -99,6 +105,8 @@ class SettingsLoader:
# load all data as is, validation is done afterwards
settings[config_id] = dict(self.config_parser[config_id])
except KeyError as e:
if allow_not_exist is True:
return {}
self.__print(
f"[!] Cannot read [{config_id}] block in the {self.config_file}: {e}",
'CRITICAL', raise_exception=True