Get warnings of options that might not exist in options.yaml

This commit is contained in:
CaitSith2
2020-11-28 14:51:13 -08:00
parent a269db6ab5
commit 8c94351d53
2 changed files with 31 additions and 19 deletions

View File

@@ -222,6 +222,23 @@ def get_default_options() -> dict:
get_default_options.options = options
return get_default_options.options
def update_options(src: dict, dest: dict, filename: str, keys: list) -> dict:
import logging
for key, value in src.items():
new_keys = keys.copy()
new_keys.append(key)
if key not in dest:
dest[key] = value
if filename.endswith("options.yaml"):
logging.info(f"Warning: {filename} is missing {'.'.join(new_keys)}")
elif isinstance(value, dict):
if not isinstance(dest.get(key, None), dict):
if filename.endswith("options.yaml"):
logging.info(f"Warning: {filename} has {'.'.join(new_keys)}, but it is not a dictionary. overwriting.")
dest[key] = value
else:
dest[key] = update_options(value, dest[key], filename, new_keys)
return dest
def get_options() -> dict:
if not hasattr(get_options, "options"):
@@ -233,14 +250,7 @@ def get_options() -> dict:
with open(location) as f:
options = parse_yaml(f.read())
default_options = get_default_options()
for key, value in options.items():
if isinstance(value, dict):
for key2, value2 in value.items():
default_options[key][key2] = value2
else:
default_options[key] = value
get_options.options = default_options
get_options.options = update_options(get_default_options(), options, location, list())
break
else:
raise FileNotFoundError(f"Could not find {locations[1]} to load options.")