def find_and_parse_config()

in postgresql_metrics/common.py [0:0]


def find_and_parse_config(config_path):
    """Finds the service configuration file and parses it.
    Checks also a directory called default, to check for default configuration values,
    that will be overwritten by the actual configuration found on given path.
    """
    config_filename = os.path.basename(config_path)
    config_root = os.path.dirname(config_path)
    default_root = os.path.join(config_root, 'default')
    config_dict = {}
    for config_dir in (default_root, config_root):
        current_path = os.path.join(config_dir, config_filename)
        if os.path.isfile(current_path):
            with open(current_path, 'r') as f:
                read_config_dict = yaml.safe_load(f)
            config_dict = merge_configs(read_config_dict, config_dict)
    return config_dict