|
|
|
|
@ -36,10 +36,11 @@ def recursive_update(target, new):
|
|
|
|
|
else:
|
|
|
|
|
target[k] = v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_defaults(data, defaults):
|
|
|
|
|
"""Recursively remove items from dict that are already in defaults"""
|
|
|
|
|
for key, value in list(data.items()): # copy the iterator, since data will be modified
|
|
|
|
|
new_value = None
|
|
|
|
|
# copy the iterator, since data will be modified
|
|
|
|
|
for key, value in list(data.items()):
|
|
|
|
|
if key in defaults:
|
|
|
|
|
if isinstance(value, dict):
|
|
|
|
|
remove_defaults(data[key], defaults[key])
|
|
|
|
|
@ -52,7 +53,7 @@ def remove_defaults(data, defaults):
|
|
|
|
|
|
|
|
|
|
class BaseJSONConfigManager(LoggingConfigurable):
|
|
|
|
|
"""General JSON config manager
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Deals with persisting/storing config in a json file with optionally
|
|
|
|
|
default values in a {section_name}.d directory.
|
|
|
|
|
"""
|
|
|
|
|
@ -82,8 +83,8 @@ class BaseJSONConfigManager(LoggingConfigurable):
|
|
|
|
|
Returns the data as a dictionary, or an empty dictionary if the file
|
|
|
|
|
doesn't exist.
|
|
|
|
|
|
|
|
|
|
When include_root is False, it will not read the root .json file, effectively
|
|
|
|
|
returning the default values.
|
|
|
|
|
When include_root is False, it will not read the root .json file,
|
|
|
|
|
effectively returning the default values.
|
|
|
|
|
"""
|
|
|
|
|
paths = [self.file_name(section_name)] if include_root else []
|
|
|
|
|
if self.read_directory:
|
|
|
|
|
@ -91,7 +92,7 @@ class BaseJSONConfigManager(LoggingConfigurable):
|
|
|
|
|
# These json files should be processed first so that the
|
|
|
|
|
# {section_name}.json take precedence.
|
|
|
|
|
# The idea behind this is that installing a Python package may
|
|
|
|
|
# put a json file somewhere in the a .d directory, while the
|
|
|
|
|
# put a json file somewhere in the a .d directory, while the
|
|
|
|
|
# .json file is probably a user configuration.
|
|
|
|
|
paths = sorted(glob.glob(pattern)) + paths
|
|
|
|
|
self.log.debug('Paths used for configuration of %s: \n\t%s', section_name, '\n\t'.join(paths))
|
|
|
|
|
|