Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5950485d46 | ||
|
|
f349927a63 | ||
|
|
dfe8890598 | ||
|
|
d224876a8e |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.43.0"
|
version = "0.43.2"
|
||||||
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"
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ class SettingsLoader:
|
|||||||
# for check settings, abort flag
|
# for check settings, abort flag
|
||||||
self.__check_settings_abort: bool = False
|
self.__check_settings_abort: bool = False
|
||||||
|
|
||||||
|
# error messages for raise ValueError
|
||||||
|
self.__error_msg: list[str] = []
|
||||||
|
|
||||||
# MARK: load settings
|
# MARK: load settings
|
||||||
def load_settings(
|
def load_settings(
|
||||||
self,
|
self,
|
||||||
@@ -87,6 +90,8 @@ class SettingsLoader:
|
|||||||
Returns:
|
Returns:
|
||||||
dict[str, str]: key = value list
|
dict[str, str]: key = value list
|
||||||
"""
|
"""
|
||||||
|
# reset error message list before run
|
||||||
|
self.__error_msg = []
|
||||||
# default set entries
|
# default set entries
|
||||||
entry_set_empty: dict[str, str | None] = {}
|
entry_set_empty: dict[str, str | None] = {}
|
||||||
# entries that have to be split
|
# entries that have to be split
|
||||||
@@ -273,7 +278,12 @@ class SettingsLoader:
|
|||||||
error = True
|
error = True
|
||||||
self.__print(f"[!] Missing content entry for: {entry}", 'ERROR')
|
self.__print(f"[!] Missing content entry for: {entry}", 'ERROR')
|
||||||
if error is True:
|
if error is True:
|
||||||
raise ValueError(self.__print("[!] Missing or incorrect settings data. Cannot proceed", 'CRITICAL'))
|
raise ValueError(
|
||||||
|
self.__print(
|
||||||
|
"[!] Missing or incorrect settings data. Cannot proceed: " + "; ".join(self.__error_msg),
|
||||||
|
'CRITICAL'
|
||||||
|
)
|
||||||
|
)
|
||||||
# set empty
|
# set empty
|
||||||
for [entry, empty_set] in entry_set_empty.items():
|
for [entry, empty_set] in entry_set_empty.items():
|
||||||
# if set, skip, else set to empty value
|
# if set, skip, else set to empty value
|
||||||
@@ -567,6 +577,9 @@ class SettingsLoader:
|
|||||||
if self.log is None or self.always_print:
|
if self.log is None or self.always_print:
|
||||||
if print_error:
|
if print_error:
|
||||||
print(msg)
|
print(msg)
|
||||||
|
if level == 'ERROR':
|
||||||
|
# remove any prefix [!] for error message list
|
||||||
|
self.__error_msg.append(msg.replace('[!] ', '').strip())
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,3 +37,6 @@ email_bad=gii@bar.com
|
|||||||
[LoadTest]
|
[LoadTest]
|
||||||
a.b.c=foo
|
a.b.c=foo
|
||||||
d:e:f=bar
|
d:e:f=bar
|
||||||
|
|
||||||
|
[ErrorTest]
|
||||||
|
some_value=42
|
||||||
|
|||||||
@@ -125,6 +125,20 @@ def main():
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(f"Could not load settings: {e}")
|
print(f"Could not load settings: {e}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
config_load = 'ErrorTest'
|
||||||
|
config_data = sl.load_settings(
|
||||||
|
config_load,
|
||||||
|
{
|
||||||
|
"some_value": [
|
||||||
|
"check:string.email.basic",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
print(f"[{config_load}] Load: {config_load} -> {dump_data(config_data)}")
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"Could not load settings: {e}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user