Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
447034046e | ||
|
|
0770ac0bb4 | ||
|
|
aa2fbd4f70 | ||
|
|
58c8447531 | ||
|
|
bcca43d774 |
@@ -1,7 +1,7 @@
|
|||||||
# MARK: Project info
|
# MARK: Project info
|
||||||
[project]
|
[project]
|
||||||
name = "corelibs"
|
name = "corelibs"
|
||||||
version = "0.12.0"
|
version = "0.12.3"
|
||||||
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"
|
||||||
|
|||||||
@@ -94,6 +94,13 @@ class SettingsLoader:
|
|||||||
try:
|
try:
|
||||||
# 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:
|
||||||
|
self.__print(
|
||||||
|
f"[!] Cannot read [{config_id}] block in the {self.config_file}: {e}",
|
||||||
|
'CRITICAL', raise_exception=True
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
for key, checks in config_validate.items():
|
for key, checks in config_validate.items():
|
||||||
skip = True
|
skip = True
|
||||||
split_char = self.DEFAULT_ELEMENT_SPLIT_CHAR
|
split_char = self.DEFAULT_ELEMENT_SPLIT_CHAR
|
||||||
@@ -145,7 +152,7 @@ class SettingsLoader:
|
|||||||
]
|
]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
self.__print(
|
self.__print(
|
||||||
f"[!] Cannot read [{config_id}] block in the {self.config_file}: {e}",
|
f"[!] Cannot read [{config_id}] block because the entry [{e}] could not be found",
|
||||||
'CRITICAL', raise_exception=True
|
'CRITICAL', raise_exception=True
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -175,7 +182,9 @@ class SettingsLoader:
|
|||||||
# - length: for string length
|
# - length: for string length
|
||||||
# - range: for int/float range check
|
# - range: for int/float range check
|
||||||
# mandatory check
|
# mandatory check
|
||||||
if check == "mandatory:yes" and not settings[config_id].get(entry):
|
if check == "mandatory:yes" and (
|
||||||
|
not settings[config_id].get(entry) or settings[config_id].get(entry) == ['']
|
||||||
|
):
|
||||||
error = True
|
error = True
|
||||||
self.__print(f"[!] Missing content entry for: {entry}", 'ERROR')
|
self.__print(f"[!] Missing content entry for: {entry}", 'ERROR')
|
||||||
# skip if empty none
|
# skip if empty none
|
||||||
@@ -392,7 +401,8 @@ class SettingsLoader:
|
|||||||
clean: re.Pattern[str] | None = None
|
clean: re.Pattern[str] | None = None
|
||||||
if regex_clean is not None:
|
if regex_clean is not None:
|
||||||
clean = re.compile(regex_clean, re.VERBOSE)
|
clean = re.compile(regex_clean, re.VERBOSE)
|
||||||
if not check.search(value):
|
# value must be set if clean is None, else empty value is allowed and will fail
|
||||||
|
if (clean is None and value or clean) and not check.search(value):
|
||||||
self.__print(
|
self.__print(
|
||||||
f"[!] Invalid content for '{entry}' with check '{validate}' and data: {value}",
|
f"[!] Invalid content for '{entry}' with check '{validate}' and data: {value}",
|
||||||
'ERROR', print_error
|
'ERROR', print_error
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ Dict helpers
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def mask(
|
def mask(
|
||||||
data_set: dict[str, str],
|
data_set: dict[str, str],
|
||||||
mask_keys: list[str] | None = None,
|
mask_keys: list[str] | None = None,
|
||||||
@@ -34,4 +37,22 @@ def mask(
|
|||||||
for key, value in data_set.items()
|
for key, value in data_set.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def set_entry(dict_set: dict[str, Any], key: str, value_set: Any) -> dict[str, Any]:
|
||||||
|
"""
|
||||||
|
set a new entry in the dict set
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
key {str} -- _description_
|
||||||
|
dict_set {dict[str, Any]} -- _description_
|
||||||
|
value_set {Any} -- _description_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict[str, Any] -- _description_
|
||||||
|
"""
|
||||||
|
if not dict_set.get(key):
|
||||||
|
dict_set[key] = {}
|
||||||
|
dict_set[key] = value_set
|
||||||
|
return dict_set
|
||||||
|
|
||||||
# __END__
|
# __END__
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
[TestA]
|
[TestA]
|
||||||
foo=bar
|
foo=bar
|
||||||
foobar=1
|
foobar=1
|
||||||
|
bar=st
|
||||||
some_match=foo
|
some_match=foo
|
||||||
some_match_list=foo,bar
|
some_match_list=foo,bar
|
||||||
test_list=a,b,c,d f, g h
|
test_list=a,b,c,d f, g h
|
||||||
@@ -21,5 +22,6 @@ match_source_list=foo,bar
|
|||||||
element_a=Static energy
|
element_a=Static energy
|
||||||
element_b=123.5
|
element_b=123.5
|
||||||
element_c=True
|
element_c=True
|
||||||
email=foo@bar.com,other+bar-fee@domain-com.cp
|
email=foo@bar.com,other+bar-fee@domain-com.cp,
|
||||||
email_bad=@bar.com
|
email_not_mandatory=
|
||||||
|
email_bad=gii@bar.com
|
||||||
|
|||||||
@@ -42,8 +42,10 @@ def main():
|
|||||||
config_data = sl.load_settings(
|
config_data = sl.load_settings(
|
||||||
config_load,
|
config_load,
|
||||||
{
|
{
|
||||||
|
# "doesnt": ["split:,"],
|
||||||
"foo": ["mandatory:yes"],
|
"foo": ["mandatory:yes"],
|
||||||
"foobar": ["check:int"],
|
"foobar": ["check:int"],
|
||||||
|
"bar": ["mandatory:yes"],
|
||||||
"some_match": ["matching:foo|bar"],
|
"some_match": ["matching:foo|bar"],
|
||||||
"some_match_list": ["split:,", "matching:foo|bar"],
|
"some_match_list": ["split:,", "matching:foo|bar"],
|
||||||
"test_list": [
|
"test_list": [
|
||||||
@@ -82,6 +84,11 @@ def main():
|
|||||||
"mandatory:yes",
|
"mandatory:yes",
|
||||||
"check:string.email.basic"
|
"check:string.email.basic"
|
||||||
],
|
],
|
||||||
|
"email_not_mandatory": [
|
||||||
|
"split:,",
|
||||||
|
# "mandatory:yes",
|
||||||
|
"check:string.email.basic"
|
||||||
|
],
|
||||||
"email_bad": [
|
"email_bad": [
|
||||||
"split:,",
|
"split:,",
|
||||||
"mandatory:yes",
|
"mandatory:yes",
|
||||||
|
|||||||
Reference in New Issue
Block a user