예제 #1
0
def upgrade_configs(project_dir, logger, to_version=None):
    """upgrade project and the user config file"""

    project = Project(project_dir=project_dir, create_config_file=True)

    if to_version is None:
        to_version = LATEST_VERSION

    user_config = copy.deepcopy(project.user_config)
    if int(user_config['version']) < int(LATEST_VERSION):
        user_config = upgrade_config(user_config, ConfigContext.USER)
        write_config(user_config, project.user_config_file_path)

    if project.legacy_config_path is not None:

        legacy_config = load_config(project.legacy_config_path)
        legacy_version = legacy_config['version']
        if int(legacy_version) > int(LAST_NO_USER_CONFIG_VERSION):
            raise KeyError(
                "Unkown legacy version {legacy_version} at {legacy_config}".format(
                    legacy_version=legacy_version,
                    legacy_config=legacy_config
                )
            )
        elif int(legacy_version) < int(LAST_NO_USER_CONFIG_VERSION):
            legacy_config = upgrade_config(
                legacy_config, ConfigContext.LEGACY, LAST_NO_USER_CONFIG_VERSION
            )

        shutil.move(
            project.legacy_config_path,
            project.legacy_config_path + ".orig"
        )
        write_config(legacy_config, project.config_file_path)
        project.reload_config()

    project_config = copy.deepcopy(project.project_config)
    if int(project_config['version']) < int(LATEST_VERSION):
        project_config = upgrade_config(project_config, ConfigContext.USER)
        write_config(project_config, project.config_file_path)

    project.reload_config()
    project.clean_config()
예제 #2
0
def test_default_config_upgrade(from_to_version, use_config_object):
    from_version, to_version = from_to_version
    base_initial_config = load_default_config(version=from_version)
    expected_config = load_default_config(version=to_version)

    if use_config_object:
        config_schema = load_config_schema(version=from_version)
        initial_config = Config(base_initial_config, schema=config_schema)
    else:
        initial_config = base_initial_config

    upgraded_config = upgrade_config(initial_config, to_version=to_version)
    assert upgraded_config == expected_config
def test_legacy_config_upgrade(project, from_to_version, use_config_object):
    from_version, to_version = from_to_version
    base_initial_config = load_default_config(version=from_version)
    expected_config = load_default_config(version=to_version)

    if use_config_object:
        config_schema = load_config_schema(version=from_version)
        initial_config = Config(base_initial_config, schema=config_schema)
    else:
        initial_config = base_initial_config

    upgraded_config = upgrade_config(initial_config, ConfigContext.LEGACY, to_version=to_version)
    assert upgraded_config == expected_config
예제 #4
0
def config_upgrade(ctx, to_version):
    """
    Upgrades the current populus config file to the specifed version.
    """
    logger = logging.getLogger('populus.cli.config.upgrade')
    project = ctx.obj['PROJECT']

    from_version = project.config['version']
    if from_version == LATEST_VERSION:
        logger.info("Already at latest version: v{0}".format(from_version))
        return

    upgraded_config = upgrade_config(project.config, to_version=to_version)
    logger.info("Upgraded config from v{0} -> v{1}".format(
        from_version, to_version))
    project.config = upgraded_config
    config_file_path = project.write_config()
    logger.info("Wrote updated config to: `{0}`".format(config_file_path))
예제 #5
0
def upgrade_configs(project_dir, logger, to_version):
    """upgrade project and the user config file"""

    user_config_file_path = get_user_json_config_file_path()
    if os.path.exists(user_config_file_path):
        user_config = load_config(user_config_file_path)
        current_user_config_version = int(user_config['version'])

        if current_user_config_version < int(LATEST_VERSION):
            upgraded_user_config = upgrade_user_config(user_config, to_version)
            if upgrade_config:
                write_config(upgraded_user_config, user_config_file_path)
            else:
                os.remove(user_config_file_path)

    legacy_config_file_path = get_legacy_json_config_file_path(project_dir)
    project_config_file_path = get_json_config_file_path(project_dir)

    if os.path.exists(legacy_config_file_path):
        legacy_config = load_config(legacy_config_file_path)
        legacy_version = legacy_config['version']

        if int(legacy_version) > int(LAST_NO_USER_CONFIG_VERSION):
            raise KeyError(
                "Unkown legacy version {legacy_version} at {legacy_config}".
                format(legacy_version=legacy_version,
                       legacy_config=legacy_config))
        elif int(legacy_version) < int(LAST_NO_USER_CONFIG_VERSION):
            upgraded_legacy_config = upgrade_config(
                legacy_config, ConfigContext.LEGACY,
                LAST_NO_USER_CONFIG_VERSION)
            write_config(upgraded_legacy_config, legacy_config_file_path)

    has_project_config = os.path.exists(project_config_file_path)
    has_legacy_config = os.path.exists(legacy_config_file_path)

    if has_project_config or has_legacy_config:
        if has_project_config:
            project_config = load_config(project_config_file_path)
        elif has_legacy_config:
            project_config = load_config(legacy_config_file_path)
        else:
            raise Exception("Invariant")
        project_config_version = int(project_config['version'])

        if project_config_version < int(LATEST_VERSION):
            upgraded_project_config = upgrade_config(
                project_config,
                ConfigContext.USER,
                to_version,
            )
            if upgraded_project_config:
                write_config(upgraded_project_config, project_config_file_path)
            elif has_project_config:
                os.remove(project_config_file_path)

    if os.path.exists(
            legacy_config_file_path) and to_version in KNOWN_USER_VERSIONS:
        os.rename(
            legacy_config_file_path,
            "{0}.backup".format(legacy_config_file_path),
        )
예제 #6
0
파일: upgrade.py 프로젝트: miohtama/populus
def upgrade_configs(project_dir, logger, to_version):
    """upgrade project and the user config file"""

    user_config_file_path = get_user_json_config_file_path()
    if os.path.exists(user_config_file_path):
        user_config = load_config(user_config_file_path)
        current_user_config_version = int(user_config['version'])

        if current_user_config_version < int(LATEST_VERSION):
            upgraded_user_config = upgrade_user_config(user_config, to_version)
            if upgrade_config:
                write_config(upgraded_user_config, user_config_file_path)
            else:
                os.remove(user_config_file_path)

    legacy_config_file_path = get_legacy_json_config_file_path(project_dir)
    project_config_file_path = get_json_config_file_path(project_dir)

    if os.path.exists(legacy_config_file_path):
        legacy_config = load_config(legacy_config_file_path)
        legacy_version = legacy_config['version']

        if int(legacy_version) > int(LAST_NO_USER_CONFIG_VERSION):
            raise KeyError(
                "Unkown legacy version {legacy_version} at {legacy_config}".format(
                    legacy_version=legacy_version,
                    legacy_config=legacy_config
                )
            )
        elif int(legacy_version) < int(LAST_NO_USER_CONFIG_VERSION):
            upgraded_legacy_config = upgrade_config(
                legacy_config,
                ConfigContext.LEGACY,
                LAST_NO_USER_CONFIG_VERSION
            )
            write_config(upgraded_legacy_config, legacy_config_file_path)

    has_project_config = os.path.exists(project_config_file_path)
    has_legacy_config = os.path.exists(legacy_config_file_path)

    if has_project_config or has_legacy_config:
        if has_project_config:
            project_config = load_config(project_config_file_path)
        elif has_legacy_config:
            project_config = load_config(legacy_config_file_path)
        else:
            raise Exception("Invariant")
        project_config_version = int(project_config['version'])

        if project_config_version < int(LATEST_VERSION):
            upgraded_project_config = upgrade_config(
                project_config,
                ConfigContext.USER,
                to_version,
            )
            if upgraded_project_config:
                write_config(upgraded_project_config, project_config_file_path)
            elif has_project_config:
                os.remove(project_config_file_path)

    if os.path.exists(legacy_config_file_path) and to_version in KNOWN_USER_VERSIONS:
        os.rename(
            legacy_config_file_path,
            "{0}.backup".format(legacy_config_file_path),
        )