Exemplo n.º 1
0
def upgrade_user_v6_to_v7(v6_user_config):
    """
    Upgrade a v6 config file to a v7 config file.
    """
    errors = get_validation_errors(v6_user_config, version=V6)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v6_default = load_user_default_config(version=V6)
    v7_default = load_user_default_config(version=V7)

    v6_default_config = Config(v6_default)
    v6_default_config.unref()

    v7_default_config = Config(v7_default)
    v7_default_config.unref()

    if v6_user_config == v6_default_config:
        return v7_default_config

    # V7 just moved to user config, no change in keys
    upgraded_v6_user_config = copy.deepcopy(v6_user_config)
    upgraded_v6_user_config['version'] = V7

    return upgraded_v6_user_config
Exemplo n.º 2
0
def upgrade_user_v7_to_v8(v7_user_config):
    """
    Upgrade a v7 user config file to a v8 user config file.
    """
    errors = get_validation_errors(v7_user_config, version=V7)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v7_default = load_user_default_config(version=V7)

    v7_default_config = Config(v7_default)

    if v7_user_config == v7_default_config:
        return {}

    # V8 just removes all of the `$ref` values from the config.
    upgraded_v7_user_config = Config(copy.deepcopy(v7_user_config))
    upgraded_v7_user_config.unref()
    upgraded_v7_user_config['version'] = V8

    return upgraded_v7_user_config
Exemplo n.º 3
0
def upgrade_v7_to_v8(v7_config):
    """
    Upgrade a v7 config file to a v8 config file.
    """
    errors = get_validation_errors(v7_config, version=V7)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors), ))

    v7_default = load_default_config(version=V7)

    v7_default_config = Config(v7_default)

    v8_default = load_default_config(version=V8)
    v8_default_config = Config(v8_default)
    v8_default_config.unref()

    if v7_config == v7_default_config:
        return v8_default_config

    # V8 just removes all of the `$ref` values from the config.
    upgraded_v7_config = Config(copy.deepcopy(v7_config))
    upgraded_v7_config.unref()
    upgraded_v7_config['version'] = V8

    return upgraded_v7_config
Exemplo n.º 4
0
Arquivo: v6.py Projeto: zutobg/populus
def upgrade_user_v6_to_v7(v6_user_config):
    """
    Upgrade a v6 config file to a v7 config file.
    """
    errors = get_validation_errors(v6_user_config, version=V6)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors), ))

    v6_default = load_user_default_config(version=V6)
    v7_default = load_user_default_config(version=V7)

    v6_default_config = Config(v6_default)
    v6_default_config.unref()

    v7_default_config = Config(v7_default)
    v7_default_config.unref()

    if v6_user_config == v6_default_config:
        return v7_default_config

    # V7 just moved to user config, no change in keys
    upgraded_v6_user_config = copy.deepcopy(v6_user_config)
    upgraded_v6_user_config['version'] = V7

    return upgraded_v6_user_config
Exemplo n.º 5
0
def upgrade_v2_to_v3(v2_config):
    """
    Upgrade a v2 config file to a v3 config file.
    """
    errors = get_validation_errors(v2_config, version=V2)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors), ))

    v2_default_config = load_default_config(version=V2)
    v3_default_config = load_default_config(version=V3)

    if v2_config == v2_default_config:
        return v3_default_config

    upgraded_v2_config = copy.deepcopy(v2_config)

    for key_path in NEW_V3_PATHS:
        if has_nested_key(upgraded_v2_config, key_path):
            continue
        set_nested_key(
            upgraded_v2_config,
            key_path,
            get_nested_key(v3_default_config, key_path),
        )

    # bump the version
    set_nested_key(upgraded_v2_config, 'version', V3)

    errors = get_validation_errors(upgraded_v2_config, version=V3)
    if errors:
        raise ValueError("Upgraded configuration did not pass validation:\n\n"
                         "\n=============Original-Configuration============\n"
                         "{0}"
                         "\n=============Upgraded-Configuration============\n"
                         "{1}"
                         "\n=============Validation-Errors============\n"
                         "{2}".format(
                             pprint.pformat(dict(v2_config)),
                             pprint.pformat(dict(upgraded_v2_config)),
                             format_errors(errors),
                         ))

    return upgraded_v2_config
Exemplo n.º 6
0
def upgrade_v1_to_v2(v1_config):
    """
    Upgrade a v1 config file to a v2 config file.
    """
    errors = get_validation_errors(v1_config, version=V1)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v1_default_config = load_default_config(version=V1)
    v2_default_config = load_default_config(version=V2)

    if v1_config == v1_default_config:
        return v2_default_config

    upgraded_v1_config = copy.deepcopy(v1_config)

    for key_path in NEW_V2_PATHS:
        if has_nested_key(upgraded_v1_config, key_path):
            continue
        set_nested_key(
            upgraded_v1_config,
            key_path,
            get_nested_key(v2_default_config, key_path),
        )

    for old_path, new_path in V2_TRANSLATIONS.items():
        if not has_nested_key(upgraded_v1_config, old_path):
            continue
        set_nested_key(
            upgraded_v1_config,
            new_path,
            pop_nested_key(upgraded_v1_config, old_path),
        )

    for key_path in V2_UPDATES:
        if not has_nested_key(upgraded_v1_config, key_path):
            continue
        current_value = get_nested_key(upgraded_v1_config, key_path)
        old_default_value = get_nested_key(v1_default_config, key_path)

        if current_value == old_default_value:
            set_nested_key(
                upgraded_v1_config,
                key_path,
                get_nested_key(v2_default_config, key_path),
            )

    # bump the version
    set_nested_key(upgraded_v1_config, 'version', V2)

    errors = get_validation_errors(upgraded_v1_config, version=V2)
    if errors:
        raise ValueError(
            "Upgraded configuration did not pass validation:\n\n"
            "\n=============Original-Configuration============\n"
            "{0}"
            "\n=============Upgraded-Configuration============\n"
            "{1}"
            "\n=============Validation-Errors============\n"
            "{2}".format(
                pprint.pformat(dict(v1_config)),
                pprint.pformat(dict(upgraded_v1_config)),
                format_errors(errors),
            )
        )

    return upgraded_v1_config
Exemplo n.º 7
0
Arquivo: v3.py Projeto: zutobg/populus
def upgrade_v3_to_v4(v3_config):
    """
    Upgrade a v3 config file to a v4 config file.
    """
    errors = get_validation_errors(v3_config, version=V3)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors), ))

    v3_default_config = load_default_config(version=V3)
    v4_default_config = load_default_config(version=V4)

    if v3_config == v3_default_config:
        return v4_default_config

    upgraded_v3_config = copy.deepcopy(v3_config)

    for key_path in NEW_V4_PATHS:
        if has_nested_key(upgraded_v3_config, key_path):
            continue
        set_nested_key(
            upgraded_v3_config,
            key_path,
            get_nested_key(v4_default_config, key_path),
        )

    for old_path, new_path in MOVED_V3_PATHS.items():
        default_value = get_nested_key(v4_default_config, new_path)

        if has_nested_key(upgraded_v3_config, old_path):
            existing_value = pop_nested_key(upgraded_v3_config, old_path)

            if is_dict(default_value) and is_dict(existing_value):
                merged_value = deep_merge_dicts(default_value, existing_value)
            elif is_list_like(default_value) and is_list_like(existing_value):
                merged_value = list(
                    set(itertools.chain(default_value, existing_value)))
            else:
                raise ValueError("Unable to merge {0} with {1}".format(
                    type(default_value),
                    type(existing_value),
                ))

            set_nested_key(
                upgraded_v3_config,
                new_path,
                merged_value,
            )
        else:
            set_nested_key(
                upgraded_v3_config,
                new_path,
                default_value,
            )

    # bump the version
    set_nested_key(upgraded_v3_config, 'version', V4)

    errors = get_validation_errors(upgraded_v3_config, version=V4)
    if errors:
        raise ValueError("Upgraded configuration did not pass validation:\n\n"
                         "\n=============Original-Configuration============\n"
                         "{0}"
                         "\n=============Upgraded-Configuration============\n"
                         "{1}"
                         "\n=============Validation-Errors============\n"
                         "{2}".format(
                             pprint.pformat(dict(v3_config)),
                             pprint.pformat(dict(upgraded_v3_config)),
                             format_errors(errors),
                         ))

    return upgraded_v3_config
Exemplo n.º 8
0
def upgrade_v3_to_v4(v3_config):
    """
    Upgrade a v3 config file to a v4 config file.
    """
    errors = get_validation_errors(v3_config, version=V3)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v3_default_config = load_default_config(version=V3)
    v4_default_config = load_default_config(version=V4)

    if v3_config == v3_default_config:
        return v4_default_config

    upgraded_v3_config = copy.deepcopy(v3_config)

    for key_path in NEW_V4_PATHS:
        if has_nested_key(upgraded_v3_config, key_path):
            continue
        set_nested_key(
            upgraded_v3_config,
            key_path,
            get_nested_key(v4_default_config, key_path),
        )

    for old_path, new_path in MOVED_V3_PATHS.items():
        default_value = get_nested_key(v4_default_config, new_path)

        if has_nested_key(upgraded_v3_config, old_path):
            existing_value = pop_nested_key(upgraded_v3_config, old_path)

            if is_dict(default_value) and is_dict(existing_value):
                merged_value = deep_merge_dicts(default_value, existing_value)
            elif is_list_like(default_value) and is_list_like(existing_value):
                merged_value = list(set(itertools.chain(default_value, existing_value)))
            else:
                raise ValueError(
                    "Unable to merge {0} with {1}".format(
                        type(default_value),
                        type(existing_value),
                    )
                )

            set_nested_key(
                upgraded_v3_config,
                new_path,
                merged_value,
            )
        else:
            set_nested_key(
                upgraded_v3_config,
                new_path,
                default_value,
            )

    # bump the version
    set_nested_key(upgraded_v3_config, 'version', V4)

    errors = get_validation_errors(upgraded_v3_config, version=V4)
    if errors:
        raise ValueError(
            "Upgraded configuration did not pass validation:\n\n"
            "\n=============Original-Configuration============\n"
            "{0}"
            "\n=============Upgraded-Configuration============\n"
            "{1}"
            "\n=============Validation-Errors============\n"
            "{2}".format(
                pprint.pformat(dict(v3_config)),
                pprint.pformat(dict(upgraded_v3_config)),
                format_errors(errors),
            )
        )

    return upgraded_v3_config
Exemplo n.º 9
0
def upgrade_v5_to_v6(v5_config):
    """
    Upgrade a v5 config file to a v6 config file.
    """
    errors = get_validation_errors(v5_config, version=V5)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v5_default_config = load_default_config(version=V5)
    v6_default_config = load_default_config(version=V6)

    if v5_config == v5_default_config:
        return v6_default_config

    upgraded_v5_config = copy.deepcopy(v5_config)

    # new configuration values whos keys were not present in the previous
    # configuration.
    for key_path in NEW_V6_PATHS:
        if has_nested_key(upgraded_v5_config, key_path):
            continue
        set_nested_key(
            upgraded_v5_config,
            key_path,
            get_nested_key(v6_default_config, key_path),
        )

    if has_nested_key(upgraded_v5_config, 'compilation.contracts_source_dir'):
        current_contracts_source_dir = pop_nested_key(
            upgraded_v5_config,
            'compilation.contracts_source_dir',
        )
        if is_string(current_contracts_source_dir):
            contract_source_dirs = [current_contracts_source_dir]
        else:
            contract_source_dirs = current_contracts_source_dir
        set_nested_key(
            upgraded_v5_config,
            'compilation.contract_source_dirs',
            contract_source_dirs,
        )

    # bump the version
    set_nested_key(upgraded_v5_config, 'version', V6)

    errors = get_validation_errors(upgraded_v5_config, version=V6)
    if errors:
        raise ValueError(
            "Upgraded configuration did not pass validation:\n\n"
            "\n=============Original-Configuration============\n"
            "{0}"
            "\n=============Upgraded-Configuration============\n"
            "{1}"
            "\n=============Validation-Errors============\n"
            "{2}".format(
                pprint.pformat(dict(v5_config)),
                pprint.pformat(dict(upgraded_v5_config)),
                format_errors(errors),
            )
        )

    return upgraded_v5_config
Exemplo n.º 10
0
def upgrade_v4_to_v5(v4_config):
    """
    Upgrade a v4 config file to a v5 config file.
    """
    errors = get_validation_errors(v4_config, version=V4)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors), ))

    v4_default_config = load_default_config(version=V4)
    v5_default_config = load_default_config(version=V5)

    if v4_config == v4_default_config:
        return v5_default_config

    upgraded_v4_config = copy.deepcopy(v4_config)

    # new configuration values whos keys were not present in the previous
    # configuration.
    for key_path in NEW_V5_PATHS:
        if has_nested_key(upgraded_v4_config, key_path):
            continue
        set_nested_key(
            upgraded_v4_config,
            key_path,
            get_nested_key(v5_default_config, key_path),
        )

    # keys in the new configuration that were relocated.
    for old_path, new_path in MOVED_V4_PATHS.items():
        default_value = get_nested_key(v5_default_config, new_path)

        if has_nested_key(upgraded_v4_config, old_path):
            existing_value = pop_nested_key(upgraded_v4_config, old_path)

            if is_dict(default_value) and is_dict(existing_value):
                merged_value = deep_merge_dicts(default_value, existing_value)
            elif is_list_like(default_value) and is_list_like(existing_value):
                merged_value = list(
                    set(itertools.chain(default_value, existing_value)))
            else:
                raise ValueError("Unable to merge {0} with {1}".format(
                    type(default_value),
                    type(existing_value),
                ))

            set_nested_key(
                upgraded_v4_config,
                new_path,
                merged_value,
            )
        else:
            set_nested_key(
                upgraded_v4_config,
                new_path,
                default_value,
            )

    # keys from the previous configuration that were changed.
    for key_path in MODIFIED_V4_PATHS:
        new_default = get_nested_key(v5_default_config, key_path)
        if key_path not in upgraded_v4_config:
            set_nested_key(
                upgraded_v4_config,
                key_path,
                new_default,
            )
        else:
            current_value = get_nested_key(upgraded_v4_config, key_path)
            old_default = get_nested_key(v4_default_config, key_path)
            if current_value == old_default:
                set_nested_key(
                    upgraded_v4_config,
                    key_path,
                    new_default,
                )

    # bump the version
    set_nested_key(upgraded_v4_config, 'version', V5)

    errors = get_validation_errors(upgraded_v4_config, version=V5)
    if errors:
        raise ValueError("Upgraded configuration did not pass validation:\n\n"
                         "\n=============Original-Configuration============\n"
                         "{0}"
                         "\n=============Upgraded-Configuration============\n"
                         "{1}"
                         "\n=============Validation-Errors============\n"
                         "{2}".format(
                             pprint.pformat(dict(v4_config)),
                             pprint.pformat(dict(upgraded_v4_config)),
                             format_errors(errors),
                         ))

    return upgraded_v4_config
Exemplo n.º 11
0
def upgrade_v5_to_v6(v5_config):
    """
    Upgrade a v5 config file to a v6 config file.
    """
    errors = get_validation_errors(v5_config, version=V5)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v5_default_config = load_default_config(version=V5)
    v6_default_config = load_default_config(version=V6)

    if v5_config == v5_default_config:
        return v6_default_config

    upgraded_v5_config = copy.deepcopy(v5_config)

    # new configuration values whos keys were not present in the previous
    # configuration.
    for key_path in NEW_V6_PATHS:
        if has_nested_key(upgraded_v5_config, key_path):
            continue
        set_nested_key(
            upgraded_v5_config,
            key_path,
            get_nested_key(v6_default_config, key_path),
        )

    if has_nested_key(upgraded_v5_config, 'compilation.contracts_source_dir'):
        current_contracts_source_dir = pop_nested_key(
            upgraded_v5_config,
            'compilation.contracts_source_dir',
        )
        if is_string(current_contracts_source_dir):
            contract_source_dirs = [current_contracts_source_dir]
        else:
            contract_source_dirs = current_contracts_source_dir
        set_nested_key(
            upgraded_v5_config,
            'compilation.contract_source_dirs',
            contract_source_dirs,
        )

    # bump the version
    set_nested_key(upgraded_v5_config, 'version', V6)

    errors = get_validation_errors(upgraded_v5_config, version=V6)
    if errors:
        raise ValueError(
            "Upgraded configuration did not pass validation:\n\n"
            "\n=============Original-Configuration============\n"
            "{0}"
            "\n=============Upgraded-Configuration============\n"
            "{1}"
            "\n=============Validation-Errors============\n"
            "{2}".format(
                pprint.pformat(dict(v5_config)),
                pprint.pformat(dict(upgraded_v5_config)),
                format_errors(errors),
            )
        )

    return upgraded_v5_config
Exemplo n.º 12
0
def upgrade_v4_to_v5(v4_config):
    """
    Upgrade a v4 config file to a v5 config file.
    """
    errors = get_validation_errors(v4_config, version=V4)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v4_default_config = load_default_config(version=V4)
    v5_default_config = load_default_config(version=V5)

    if v4_config == v4_default_config:
        return v5_default_config

    upgraded_v4_config = copy.deepcopy(v4_config)

    # new configuration values whos keys were not present in the previous
    # configuration.
    for key_path in NEW_V5_PATHS:
        if has_nested_key(upgraded_v4_config, key_path):
            continue
        set_nested_key(
            upgraded_v4_config,
            key_path,
            get_nested_key(v5_default_config, key_path),
        )

    # keys in the new configuration that were relocated.
    for old_path, new_path in MOVED_V4_PATHS.items():
        default_value = get_nested_key(v5_default_config, new_path)

        if has_nested_key(upgraded_v4_config, old_path):
            existing_value = pop_nested_key(upgraded_v4_config, old_path)

            if is_dict(default_value) and is_dict(existing_value):
                merged_value = deep_merge_dicts(default_value, existing_value)
            elif is_list_like(default_value) and is_list_like(existing_value):
                merged_value = list(set(itertools.chain(default_value, existing_value)))
            else:
                raise ValueError(
                    "Unable to merge {0} with {1}".format(
                        type(default_value),
                        type(existing_value),
                    )
                )

            set_nested_key(
                upgraded_v4_config,
                new_path,
                merged_value,
            )
        else:
            set_nested_key(
                upgraded_v4_config,
                new_path,
                default_value,
            )

    # keys from the previous configuration that were changed.
    for key_path in MODIFIED_V4_PATHS:
        new_default = get_nested_key(v5_default_config, key_path)
        if key_path not in upgraded_v4_config:
            set_nested_key(
                upgraded_v4_config,
                key_path,
                new_default,
            )
        else:
            current_value = get_nested_key(upgraded_v4_config, key_path)
            old_default = get_nested_key(v4_default_config, key_path)
            if current_value == old_default:
                set_nested_key(
                    upgraded_v4_config,
                    key_path,
                    new_default,
                )

    # bump the version
    set_nested_key(upgraded_v4_config, 'version', V5)

    errors = get_validation_errors(upgraded_v4_config, version=V5)
    if errors:
        raise ValueError(
            "Upgraded configuration did not pass validation:\n\n"
            "\n=============Original-Configuration============\n"
            "{0}"
            "\n=============Upgraded-Configuration============\n"
            "{1}"
            "\n=============Validation-Errors============\n"
            "{2}".format(
                pprint.pformat(dict(v4_config)),
                pprint.pformat(dict(upgraded_v4_config)),
                format_errors(errors),
            )
        )

    return upgraded_v4_config