Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70e8ceecce | ||
|
|
acbe1ac692 | ||
|
|
99bca2c467 |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.12.4"
|
version = "0.12.5"
|
||||||
description = "Collection of utils for Python scripts"
|
description = "Collection of utils for Python scripts"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
|
|||||||
@@ -66,7 +66,12 @@ class SettingsLoader:
|
|||||||
self._check_settings_abort: bool = False
|
self._check_settings_abort: bool = False
|
||||||
|
|
||||||
# MARK: load settings
|
# 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
|
neutral settings loader
|
||||||
|
|
||||||
@@ -84,9 +89,12 @@ class SettingsLoader:
|
|||||||
- convert: convert to int, float -> if element is number convert, else leave as is
|
- convert: convert to int, float -> if element is number convert, else leave as is
|
||||||
- empty: convert empty to, if nothing set on the right side then convert to None type
|
- empty: convert empty to, if nothing set on the right side then convert to None type
|
||||||
|
|
||||||
|
TODO: there should be a config/options argument for general settings
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config_id (str): what block to load
|
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:
|
Returns:
|
||||||
dict[str, str]: key = value list
|
dict[str, str]: key = value list
|
||||||
@@ -99,6 +107,8 @@ class SettingsLoader:
|
|||||||
# load all data as is, validation is done afterwards
|
# load all data as is, validation is done afterwards
|
||||||
settings[config_id] = dict(self.config_parser[config_id])
|
settings[config_id] = dict(self.config_parser[config_id])
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
|
if allow_not_exist is True:
|
||||||
|
return {}
|
||||||
self.__print(
|
self.__print(
|
||||||
f"[!] Cannot read [{config_id}] block in the {self.config_file}: {e}",
|
f"[!] Cannot read [{config_id}] block in the {self.config_file}: {e}",
|
||||||
'CRITICAL', raise_exception=True
|
'CRITICAL', raise_exception=True
|
||||||
|
|||||||
Reference in New Issue
Block a user