Example #1
0
def get_configuration(defaults=DEFAULT_SETTINGS):
    """Reads command line arguments and a YAML configuration file, and
    returns a dict of settings.

    """
    # We need to read the command-line arguments first to determine the
    # configuration directory and mount point, but we merge them last
    # into the main configuration so they have the highest precedence.
    arg_conf = read_command_line()
    path = arg_conf.pop("config-file")
    mount_point = expandpath(arg_conf["mount-point"])
    arg_conf["mount-point"] = mount_point

    default_conf, mount_point_conf = read_configuration_file(path, mount_point)

    merged_conf = dict(defaults)
    merge_dicts(merged_conf, default_conf)
    merge_dicts(merged_conf, mount_point_conf)
    merge_dicts(merged_conf, arg_conf)

    if merged_conf.get("no-input", False):
        validate_missing_information(merged_conf)
    else:
        merged_conf = request_missing_information(merged_conf)

    return merged_conf
Example #2
0
def get_configuration(defaults=DEFAULT_SETTINGS):
    """Reads command line arguments and a YAML configuration file, and
    returns a dict of settings.

    """
    # We need to read the command-line arguments first to determine the
    # configuration directory and mount point, but we merge them last
    # into the main configuration so they have the highest precedence.
    arg_conf = read_command_line()
    path = arg_conf.pop('config-file')
    mount_point = expandpath(arg_conf['mount-point'])
    arg_conf['mount-point'] = mount_point

    default_conf, mount_point_conf = read_configuration_file(path, mount_point)

    merged_conf = dict(defaults)
    merge_dicts(merged_conf, default_conf)
    merge_dicts(merged_conf, mount_point_conf)
    merge_dicts(merged_conf, arg_conf)

    if merged_conf.get('no-input', False):
        validate_missing_information(merged_conf)
    else:
        merged_conf = request_missing_information(merged_conf)

    return merged_conf
Example #3
0
def read_configuration_file(path, mount_point):
    """Reads the YAML file at the location `path`, and returns a pair of
    dicts. The first dict contains the default settings for all mount points,
    while the second contains settings for the selected mount point.

    """

    path = expandpath(path)

    if not os.path.exists(path):
        return {}, {}

    with open(path, "r") as f:
        conf = yaml.load(f)

    default_conf = conf.get("defaults", {})
    mount_points = conf.get("mount-points", {})

    # Expand all mount points to their absolute paths before comparing
    # against the selected mount point (which is already expanded.)
    mount_points = map_dict(mount_points, lambda k, v: (expandpath(k), v))
    mount_point_conf = mount_points.get(mount_point, {})

    return default_conf, mount_point_conf
Example #4
0
def read_configuration_file(path, mount_point):
    """Reads the YAML file at the location `path`, and returns a pair of
    dicts. The first dict contains the default settings for all mount points,
    while the second contains settings for the selected mount point.

    """

    path = expandpath(path)

    if not os.path.exists(path):
        return {}, {}

    with open(path, 'r') as f:
        conf = yaml.load(f)

    default_conf = conf.get('defaults', {})
    mount_points = conf.get('mount-points', {})

    # Expand all mount points to their absolute paths before comparing
    # against the selected mount point (which is already expanded.)
    mount_points = map_dict(mount_points, lambda k, v: (expandpath(k), v))
    mount_point_conf = mount_points.get(mount_point, {})

    return default_conf, mount_point_conf