Given a list of PathConfig objects, merges them into a single PathConfig,
    giving priority in the order of the configs (first has highest priority).

def merge_path_config(configs, config_dir_override):
    """
    Given a list of PathConfig objects, merges them into a single PathConfig,
    giving priority in the order of the configs (first has highest priority).
    """
    config_dir = None
    log_dir = None
    data_dir = None
    key_dir = None
    policy_dir = None

    for config in reversed(configs):
        if config.config_dir is not None:
            config_dir = config.config_dir
        if config.log_dir is not None:
            log_dir = config.log_dir
        if config.data_dir is not None:
            data_dir = config.data_dir
        if config.key_dir is not None:
            key_dir = config.key_dir
        if config.policy_dir is not None:
            policy_dir = config.policy_dir

    if config_dir_override is not None:
        config_dir = config_dir_override

    return PathConfig(
        config_dir=config_dir,
        log_dir=log_dir,
        data_dir=data_dir,
        key_dir=key_dir,
        policy_dir=policy_dir)