libs: replace libs.toml.dict_to_toml with libs.faults.resolve_faults
All checks were successful
bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2021-04-24 09:39:08 +02:00
parent 4e175e998e
commit 2667a2c00d
Signed by: kunsi
GPG key ID: 12E3D2136B818350
4 changed files with 8 additions and 21 deletions

View file

@ -1,4 +1,4 @@
<%
from tomlkit import dumps as toml_dumps
from bundlewrap.utils.text import toml_clean
%>${toml_clean(toml_dumps(repo.libs.toml.dict_to_toml(node.metadata['simple-icinga-dashboard'])))}
%>${toml_clean(toml_dumps(repo.libs.faults.resolve_faults(node.metadata['simple-icinga-dashboard']), sort_keys=True))}

View file

@ -1,4 +1,4 @@
<%
from tomlkit import dumps as toml_dumps
from bundlewrap.utils.text import toml_clean
%>${toml_clean(toml_dumps(repo.libs.toml.dict_to_toml(config)))}
%>${toml_clean(toml_dumps(repo.libs.faults.resolve_faults(config), sort_keys=True))}

6
libs/faults.py Normal file
View file

@ -0,0 +1,6 @@
from json import loads, dumps
from bundlewrap.metadata import metadata_to_json
def resolve_faults(dictionary: dict) -> dict:
return loads(metadata_to_json(dictionary))

View file

@ -1,19 +0,0 @@
from tomlkit import document as toml_document
from bundlewrap.utils import Fault
# Copied from bw core, because bw core doesn't support faults
def dict_to_toml(dict_obj):
toml_doc = toml_document()
for key, value in sorted(dict_obj.items()):
if isinstance(value, tuple):
toml_doc[key] = list(value)
elif isinstance(value, set):
toml_doc[key] = sorted(value)
elif isinstance(value, dict):
toml_doc[key] = dict_to_toml(value)
elif isinstance(value, Fault):
toml_doc[key] = str(value)
else:
toml_doc[key] = value
return toml_doc