WIP: default config replacement for (#12)

This commit is contained in:
2023-03-16 16:32:26 +01:00
parent 4ec69c2a05
commit b5e3abd4ad
5 changed files with 142 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
from os import kill
from os import kill, path
from os import name as osname
from os import sep
from sys import exit
@@ -73,9 +73,20 @@ def configGet(key: str, *args: str):
* any: Value of provided key
"""
this_dict = jsonLoad("config.json")
this_key = this_dict
for dict_key in args:
this_key = this_key[dict_key]
try:
this_key = this_dict
for dict_key in args:
this_key = this_key[dict_key]
except KeyError:
print(
f"Could not find config key '{key}' under path {args}: falling back to default config",
flush=True,
)
fallback_dict = jsonLoad(path.join("modules", "default_config.json"))
this_key = fallback_dict
for dict_key in args:
this_key = this_key[dict_key]
configSet(key, this_key[key], args)
return this_key[key]