def read_configuration(cligraph, custom_suffix=''):
"""Read configuration dict for the given tool
"""
cfg = {}
layers = collections.OrderedDict()
layers['auto'] = [automatic_configuration, None]
layers['shared'] = [os.path.join(cligraph.tool_path, 'conf/%s.yaml' % cligraph.tool_shortname), None]
layers['custom'] = [os.path.join(os.path.abspath(os.path.expanduser('~/.' + cligraph.tool_shortname)), '%s.yaml%s' % (cligraph.tool_shortname, custom_suffix)), None]
for layer_name, layer_data in layers.items():
if callable(layer_data[0]):
layer = layer_data[0](cligraph, layer_name)
else:
if not os.path.exists(layer_data[0]):
continue
with open(layer_data[0], 'r') as filep:
layer = yaml.load(filep, Loader=Loader)
layers[layer_name][1] = layer
if layer:
update_recursive(cfg, layer)
resolve_config(cfg)
return AttrDict(**cfg), layers
评论列表
文章目录