From 57377fe9245ec53a7caa366a837494e37a293dee Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Tue, 21 Jun 2022 22:46:53 +0200 Subject: [PATCH] [REF] merge version and release concept and simplify version settings --- README.md | 16 +- odoo_openupgrade_wizard/cli_docker_build.py | 14 +- .../cli_generate_module_analysis.py | 6 +- odoo_openupgrade_wizard/cli_get_code.py | 10 +- odoo_openupgrade_wizard/cli_init.py | 34 ++-- odoo_openupgrade_wizard/cli_options.py | 18 +- .../configuration_version_dependant.py | 114 +++++++----- odoo_openupgrade_wizard/templates.py | 45 +++-- odoo_openupgrade_wizard/tools_odoo.py | 44 ++--- odoo_openupgrade_wizard/tools_odoo_module.py | 162 +++++++++--------- tests/cli_01_init_test.py | 4 +- tests/cli_03_docker_build_test.py | 2 +- tests/cli_21_generate_module_analysis_test.py | 2 +- tests/data/output_expected/config.yml | 15 +- 14 files changed, 246 insertions(+), 240 deletions(-) diff --git a/README.md b/README.md index 220e692..e465d66 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ in ``DEVELOP.md`` file.) ``` odoo-openupgrade-wizard init\ - --initial-release=10.0\ - --final-release=12.0\ + --initial-version=10.0\ + --final-version=12.0\ --project-name=my-customer-10-12\ --extra-repository=OCA/web,OCA/server-tools ``` @@ -158,10 +158,10 @@ The code is defined in the ``repos.yml`` of each sub folders. **Optional arguments** -if you want to update the code of some given releases, you can provide an extra parameter: +if you want to update the code of some given versions, you can provide an extra parameter: ``` -odoo-openupgrade-wizard get-code --releases 10.0,11.0 +odoo-openupgrade-wizard get-code --versions 10.0,11.0 ``` @@ -190,8 +190,8 @@ odoo-openupgrade-wizard-image---my-customer-10-12---10.0 latest 9d94dce2bd4 **Optional arguments** -* if you want to (re)build an image for some given releases, you can provide - an extra parameter: ``--releases 10.0,12.0`` +* if you want to (re)build an image for some given versions, you can provide + an extra parameter: ``--versions 10.0,12.0`` **Note** @@ -256,8 +256,8 @@ odoo-openupgrade-wizard upgrade\ --database DB_NAME ``` -Realize an upgrade of the database from the initial release to -the final release, following the different steps. +Realize an upgrade of the database from the initial version to +the final version, following the different steps. For each step, it will : diff --git a/odoo_openupgrade_wizard/cli_docker_build.py b/odoo_openupgrade_wizard/cli_docker_build.py index 9a78db2..2543794 100644 --- a/odoo_openupgrade_wizard/cli_docker_build.py +++ b/odoo_openupgrade_wizard/cli_docker_build.py @@ -3,7 +3,7 @@ from loguru import logger from odoo_openupgrade_wizard.cli_options import ( get_odoo_versions_from_options, - releases_options, + versions_options, ) from odoo_openupgrade_wizard.tools_docker import build_image, pull_image from odoo_openupgrade_wizard.tools_odoo import ( @@ -13,19 +13,19 @@ from odoo_openupgrade_wizard.tools_odoo import ( @click.command() -@releases_options +@versions_options @click.pass_context -def docker_build(ctx, releases): - """Build Odoo Docker Images. (One image per release)""" +def docker_build(ctx, versions): + """Build Odoo Docker Images. (One image per version)""" # Pull DB image pull_image(ctx.obj["config"]["postgres_image_name"]) # Build images for each odoo version - for odoo_version in get_odoo_versions_from_options(ctx, releases): + for odoo_version in get_odoo_versions_from_options(ctx, versions): logger.info( - "Building Odoo docker image for release '%s'. " - "This can take a while..." % (odoo_version["release"]) + "Building Odoo docker image for version '%s'. " + "This can take a while..." % (odoo_version) ) image = build_image( get_odoo_env_path(ctx, odoo_version), diff --git a/odoo_openupgrade_wizard/cli_generate_module_analysis.py b/odoo_openupgrade_wizard/cli_generate_module_analysis.py index 4521da4..cab86fc 100644 --- a/odoo_openupgrade_wizard/cli_generate_module_analysis.py +++ b/odoo_openupgrade_wizard/cli_generate_module_analysis.py @@ -48,11 +48,11 @@ def generate_module_analysis(ctx, step, database, modules): initial_database = "%s_%s" % ( database, - str(initial_step["release"]).replace(".", ""), + str(initial_step["version"]).replace(".", ""), ) final_database = "%s_%s" % ( database, - str(final_step["release"]).replace(".", ""), + str(final_step["version"]).replace(".", ""), ) modules = modules and modules.split(",") or [] @@ -131,7 +131,7 @@ def generate_module_analysis(ctx, step, database, modules): # group to make possible to write analysis files # for docker container user ensure_folder_writable( - get_odoo_env_path(ctx, {"release": final_step["release"]}) / "src" + get_odoo_env_path(ctx, final_step["version"]) / "src" ) generate_analysis_files( diff --git a/odoo_openupgrade_wizard/cli_get_code.py b/odoo_openupgrade_wizard/cli_get_code.py index 1e3bff3..cb85bd4 100644 --- a/odoo_openupgrade_wizard/cli_get_code.py +++ b/odoo_openupgrade_wizard/cli_get_code.py @@ -2,14 +2,14 @@ import click from odoo_openupgrade_wizard.cli_options import ( get_odoo_versions_from_options, - releases_options, + versions_options, ) from odoo_openupgrade_wizard.tools_odoo import get_odoo_env_path from odoo_openupgrade_wizard.tools_system import git_aggregate @click.command() -@releases_options +@versions_options @click.option( "-j", "--jobs", @@ -19,10 +19,10 @@ from odoo_openupgrade_wizard.tools_system import git_aggregate " reasonably set to 10 by default.", ) @click.pass_context -def get_code(ctx, releases, jobs): - """Get code by running gitaggregate command for each release""" +def get_code(ctx, versions, jobs): + """Get code by running gitaggregate command for each version""" - for odoo_version in get_odoo_versions_from_options(ctx, releases): + for odoo_version in get_odoo_versions_from_options(ctx, versions): folder_path = get_odoo_env_path(ctx, odoo_version) repo_file_path = folder_path / "repos.yml" git_aggregate(folder_path, repo_file_path, jobs) diff --git a/odoo_openupgrade_wizard/cli_init.py b/odoo_openupgrade_wizard/cli_init.py index 43902a4..51df644 100644 --- a/odoo_openupgrade_wizard/cli_init.py +++ b/odoo_openupgrade_wizard/cli_init.py @@ -5,7 +5,9 @@ import click from odoo_openupgrade_wizard import templates from odoo_openupgrade_wizard.configuration_version_dependant import ( get_odoo_versions, - get_release_options, + get_python_libraries, + get_python_major_version, + get_version_options, ) from odoo_openupgrade_wizard.tools_odoo import get_odoo_env_path from odoo_openupgrade_wizard.tools_system import ( @@ -26,16 +28,16 @@ from odoo_openupgrade_wizard.tools_system import ( " name the odoo docker images.", ) @click.option( - "--initial-release", + "--initial-version", required=True, prompt=True, - type=click.Choice(get_release_options("initial")), + type=click.Choice(get_version_options("initial")), ) @click.option( - "--final-release", + "--final-version", required=True, prompt=True, - type=click.Choice(get_release_options("final")), + type=click.Choice(get_version_options("final")), ) @click.option( "--extra-repository", @@ -46,10 +48,10 @@ from odoo_openupgrade_wizard.tools_system import ( ) @click.pass_context def init( - ctx, project_name, initial_release, final_release, extra_repository_list + ctx, project_name, initial_version, final_version, extra_repository_list ): """Initialize OpenUpgrade Wizard Environment based on the initial and - the final release of Odoo you want to migrate. + the final version of Odoo you want to migrate. """ # Handle arguments @@ -65,7 +67,7 @@ def init( # 1. Compute Odoo versions odoo_versions = get_odoo_versions( - float(initial_release), float(final_release) + float(initial_version), float(final_version) ) # 2. Compute Migration Steps @@ -75,9 +77,8 @@ def init( { "name": 1, "execution_context": "regular", - "release": odoo_versions[0]["release"], - "complete_name": "step_01__update__%s" - % (odoo_versions[0]["release"]), + "version": odoo_versions[0], + "complete_name": "step_01__update__%s" % (odoo_versions[0]), } ] @@ -88,9 +89,9 @@ def init( { "name": step_nbr, "execution_context": "openupgrade", - "release": odoo_version["release"], + "version": odoo_version, "complete_name": "step_%s__upgrade__%s" - % (str(step_nbr).rjust(2, "0"), odoo_version["release"]), + % (str(step_nbr).rjust(2, "0"), odoo_version), } ) step_nbr += 1 @@ -101,9 +102,9 @@ def init( { "name": step_nbr, "execution_context": "regular", - "release": odoo_versions[-1]["release"], + "version": odoo_versions[-1], "complete_name": "step_%s__update__%s" - % (str(step_nbr).rjust(2, "0"), odoo_versions[-1]["release"]), + % (str(step_nbr).rjust(2, "0"), odoo_versions[-1]), } ) @@ -154,7 +155,7 @@ def init( ensure_file_exists_from_template( path_version / Path("python_requirements.txt"), templates.PYTHON_REQUIREMENTS_TXT_TEMPLATE, - python_libraries=odoo_version["python_libraries"], + python_libraries=get_python_libraries(odoo_version), ) # Create debian requirements file @@ -182,6 +183,7 @@ def init( path_version / Path("Dockerfile"), templates.DOCKERFILE_TEMPLATE, odoo_version=odoo_version, + python_major_version=get_python_major_version(odoo_version), ) # Create 'src' folder that will contain all the odoo code diff --git a/odoo_openupgrade_wizard/cli_options.py b/odoo_openupgrade_wizard/cli_options.py index f1fb468..9620fee 100644 --- a/odoo_openupgrade_wizard/cli_options.py +++ b/odoo_openupgrade_wizard/cli_options.py @@ -1,14 +1,14 @@ import click -def releases_options(function): +def versions_options(function): function = click.option( - "-r", - "--releases", + "-v", + "--versions", type=str, - help="Coma-separated values of odoo releases for which" + help="Coma-separated values of odoo versions for which" " you want to perform the operation." - " Let empty to perform the operation on all the releases" + " Let empty to perform the operation on all the versions" " of the project", )(function) return function @@ -66,15 +66,15 @@ def database_option_required(function): return function -def get_odoo_versions_from_options(ctx, releases_arg): +def get_odoo_versions_from_options(ctx, versions_arg): - if not releases_arg: + if not versions_arg: return ctx.obj["config"]["odoo_versions"] else: odoo_versions = [] - releases = [float(x) for x in releases_arg.split(",")] + versions = [float(x) for x in versions_arg.split(",")] for odoo_version in ctx.obj["config"]["odoo_versions"]: - if odoo_version["release"] in releases: + if odoo_version in versions: odoo_versions.append(odoo_version) return odoo_versions diff --git a/odoo_openupgrade_wizard/configuration_version_dependant.py b/odoo_openupgrade_wizard/configuration_version_dependant.py index 675f74c..d135b89 100644 --- a/odoo_openupgrade_wizard/configuration_version_dependant.py +++ b/odoo_openupgrade_wizard/configuration_version_dependant.py @@ -4,27 +4,27 @@ from loguru import logger _ODOO_VERSION_TEMPLATES = [ { - "release": 8.0, + "version": 8.0, "python_major_version": "python2", "python_libraries": [], }, { - "release": 9.0, + "version": 9.0, "python_major_version": "python2", "python_libraries": ["openupgradelib==2.0.0"], }, { - "release": 10.0, + "version": 10.0, "python_major_version": "python2", "python_libraries": ["openupgradelib==2.0.0"], }, { - "release": 11.0, + "version": 11.0, "python_major_version": "python3", "python_libraries": ["openupgradelib==2.0.0"], }, { - "release": 12.0, + "version": 12.0, "python_major_version": "python3", "python_libraries": [ "git+https://github.com/grap/openupgradelib.git" @@ -32,25 +32,47 @@ _ODOO_VERSION_TEMPLATES = [ ], }, { - "release": 13.0, + "version": 13.0, "python_major_version": "python3", "python_libraries": ["openupgradelib"], }, { - "release": 14.0, + "version": 14.0, "python_major_version": "python3", "python_libraries": ["openupgradelib"], }, { - "release": 15.0, + "version": 15.0, "python_major_version": "python3", "python_libraries": ["openupgradelib"], }, ] -def get_release_options(mode: str) -> list: - """Get options available for release click argument. +def get_version_template(version: float) -> dict: + """return a version template dictionnary according to a version + provided""" + for version_template in _ODOO_VERSION_TEMPLATES: + if version_template["version"] == version: + return version_template + else: + raise ValueError + + +def get_python_libraries(version: float) -> list: + """Return a list of python librairies that should be + installed in each docker container for a given version""" + return get_version_template(version)["python_libraries"] + + +def get_python_major_version(version: float) -> str: + """Return the major python version (2.0, 3.0) of Odoo for + a given version""" + return get_version_template(version)["python_major_version"] + + +def get_version_options(mode: str) -> list: + """Get options available for version click argument. Arguments: mode: Possible value 'initial', 'final' Return: @@ -58,32 +80,32 @@ def get_release_options(mode: str) -> list: Exemple: ['9.0', '10.0', '11.0'] """ - releases_list = [str(x["release"]) for x in _ODOO_VERSION_TEMPLATES] + version_options = [str(x["version"]) for x in _ODOO_VERSION_TEMPLATES] if mode == "initial": - releases_list = releases_list[:-1] + version_options = version_options[:-1] if mode == "final": - releases_list = releases_list[1:] - return releases_list + version_options = version_options[1:] + return version_options -def get_odoo_versions(initial_release: float, final_release: float) -> list: - """Return a list of odoo versions from the initial release to the final - release +def get_odoo_versions(initial_version: float, final_version: float) -> list: + """Return a list of odoo versions from the initial version to the final + version """ result = [] for version_template in _ODOO_VERSION_TEMPLATES: if ( - version_template["release"] >= initial_release - and version_template["release"] <= final_release + version_template["version"] >= initial_version + and version_template["version"] <= final_version ): - result.append(version_template) + result.append(version_template["version"]) return result def get_odoo_run_command(migration_step: dict) -> str: """Return the name of the command to execute, depending on the migration step. (odoo-bin, odoo.py, etc...)""" - if migration_step["release"] >= 10.0: + if migration_step["version"] >= 10.0: return "odoo-bin" return "odoo.py" @@ -97,13 +119,13 @@ def get_odoo_folder( if execution_context == "regular": return "src/odoo" - elif execution_context == "openupgrade" and migration_step["release"] < 14: + elif execution_context == "openupgrade" and migration_step["version"] < 14: return "src/openupgrade" if migration_step["execution_context"] == "regular": return "src/odoo" - if migration_step["release"] >= 14.0: + if migration_step["version"] >= 14.0: return "src/odoo" return "src/openupgrade" @@ -112,7 +134,7 @@ def get_odoo_folder( def get_base_module_folder(migration_step: dict) -> str: """return the name of the folder (odoo, openerp, etc...) where the 'base' module is, depending on the migration_step""" - if migration_step["release"] >= 10.0: + if migration_step["version"] >= 10.0: return "odoo" return "openerp" @@ -126,13 +148,13 @@ def skip_addon_path(migration_step: dict, path: Path) -> bool: return ( str(path).endswith("/src/odoo") or str(path).endswith("src/openupgrade") - ) and migration_step["release"] < 14.0 + ) and migration_step["version"] < 14.0 def get_server_wide_modules_upgrade(migration_step: dict) -> list: """return a list of modules to load, depending on the migration step.""" if ( - migration_step["release"] >= 14.0 + migration_step["version"] >= 14.0 and migration_step["execution_context"] == "openupgrade" ): return ["openupgrade_framework"] @@ -142,7 +164,7 @@ def get_server_wide_modules_upgrade(migration_step: dict) -> list: def get_upgrade_analysis_module(migration_step: dict) -> str: """return the upgrade_analysis module name""" - if migration_step["release"] >= 14.0: + if migration_step["version"] >= 14.0: # (Module in OCA/server-tools) return "upgrade_analysis" @@ -152,10 +174,10 @@ def get_upgrade_analysis_module(migration_step: dict) -> str: def generate_records(odoo_instance, migration_step: dict): logger.info( - "Generate Records in release %s ..." - " (It can take a while)" % (migration_step["release"]) + "Generate Records in version %s ..." + " (It can take a while)" % (migration_step["version"]) ) - if migration_step["release"] < 14.0: + if migration_step["version"] < 14.0: wizard = odoo_instance.browse_by_create( "openupgrade.generate.records.wizard", {} ) @@ -167,7 +189,7 @@ def generate_records(odoo_instance, migration_step: dict): def get_installable_odoo_modules(odoo_instance, migraton_step): - if migraton_step["release"] < 14.0: + if migraton_step["version"] < 14.0: # TODO, improve that algorithm, if possible modules = odoo_instance.browse_by_search( "ir.module.module", @@ -195,14 +217,14 @@ def generate_analysis_files( " the modules installed on %s ..." % (initial_database) ) proxy_vals = { - "name": "Proxy to Previous Release", + "name": "Proxy to Previous version", "server": initial_odoo_host, "port": "8069", "database": initial_database, "username": "admin", "password": "admin", } - if final_step["release"] < 14.0: + if final_step["version"] < 14.0: logger.info("> Create proxy ...") proxy = final_odoo_instance.browse_by_create( "openupgrade.comparison.config", proxy_vals @@ -237,44 +259,44 @@ def generate_analysis_files( analysis.analyze() -def get_apriori_file_relative_path(migration_step: dict) -> (str, Path): +def get_apriori_file_relative_path(version: float) -> (str, Path): """Return the module name and the relative file path of the apriori.py file that contains all the rename and the merge information for a given upgrade.""" - if migration_step["release"] < 14.0: + if version < 14.0: return ("openupgrade_records", Path("lib/apriori.py")) else: return ("openupgrade_scripts", Path("apriori.py")) -def get_coverage_relative_path(migration_step: dict) -> (str, Path): +def get_coverage_relative_path(version: float) -> (str, Path): """Return the path of the coverage file.""" - if migration_step["release"] < 10.0: + if version < 10.0: base_path = Path("src/openupgrade/openerp/openupgrade/doc/source") - elif migration_step["release"] < 14.0: + elif version < 14.0: base_path = Path("src/openupgrade/odoo/openupgrade/doc/source") else: base_path = Path("src/openupgrade/docsource") - previous_release = migration_step["release"] - 1 + previous_version = version - 1 return base_path / Path( "modules%s-%s.rst" % ( - ("%.1f" % previous_release).replace(".", ""), - ("%.1f" % migration_step["release"]).replace(".", ""), + ("%.1f" % previous_version).replace(".", ""), + ("%.1f" % version).replace(".", ""), ) ) def get_openupgrade_analysis_files( - odoo_env_path: Path, release: float + odoo_env_path: Path, version: float ) -> dict: """return a dictionnary of module_name : path, - where module_name is the name of each module of a release + where module_name is the name of each module of a version and and path is the path of the migration_analysis.txt file of the module""" result = {} - if release < 14.0: + if version < 14.0: base_name = "openupgrade_analysis.txt" else: base_name = "upgrade_analysis.txt" @@ -286,7 +308,7 @@ def get_openupgrade_analysis_files( ] for file in files: - # this part doesn't depends only of the release + # this part doesn't depends only of the version # 14+ module can have migrations folder. if file.parent.parent.name == "migrations": module_name = file.parent.parent.parent.name @@ -294,6 +316,6 @@ def get_openupgrade_analysis_files( module_name = file.parent.parent.name result[module_name] = file logger.debug( - "Release %s : %d analysis files found." % (release, len(result)) + "Version %s : %d analysis files found." % (version, len(result)) ) return result diff --git a/odoo_openupgrade_wizard/templates.py b/odoo_openupgrade_wizard/templates.py index 94a8e60..4b503f3 100644 --- a/odoo_openupgrade_wizard/templates.py +++ b/odoo_openupgrade_wizard/templates.py @@ -1,5 +1,4 @@ -CONFIG_YML_TEMPLATE = """ -project_name: {{ project_name }} +CONFIG_YML_TEMPLATE = """project_name: {{ project_name }} postgres_image_name: postgres:13 postgres_container_name: {{project_name}}-db @@ -9,14 +8,14 @@ odoo_default_country_code: FR odoo_versions: -{% for odoo_version in odoo_versions %} - - release: {{ odoo_version['release'] }} -{% endfor %} +{%- for odoo_version in odoo_versions %} + - {{ odoo_version }} +{%- endfor %} migration_steps: -{% for step in steps %} +{%- for step in steps %} - name: {{ step['name'] }} - release: {{ step['release'] }} + version: {{ step['version'] }} execution_context: {{ step['execution_context'] }} complete_name: {{ step['complete_name'] }} {% endfor %} @@ -62,9 +61,9 @@ REPO_YML_TEMPLATE = """ depth: 1 remotes: odoo: https://github.com/odoo/odoo - target: odoo {{ odoo_version['release'] }}-target + target: odoo {{ odoo_version }}-target merges: - - odoo {{ odoo_version['release'] }} + - odoo {{ odoo_version }} ############################################################################## ## OpenUpgrade Repository @@ -75,9 +74,9 @@ REPO_YML_TEMPLATE = """ depth: 1 remotes: OCA: https://github.com/OCA/OpenUpgrade - target: OCA {{ odoo_version['release'] }}-target + target: OCA {{ odoo_version }}-target merges: - - OCA {{ odoo_version['release'] }} + - OCA {{ odoo_version }} {% for org_name, repo_list in orgs.items() %} ############################################################################## @@ -89,9 +88,9 @@ REPO_YML_TEMPLATE = """ depth: 1 remotes: {{ org_name }}: https://github.com/{{ org_name }}/{{ repo }} - target: {{ org_name }} {{ odoo_version['release'] }}-target + target: {{ org_name }} {{ odoo_version }}-target merges: - - {{ org_name }} {{ odoo_version['release'] }} + - {{ org_name }} {{ odoo_version }} {% endfor %} {% endfor %} @@ -113,10 +112,10 @@ ODOO_CONFIG_TEMPLATE = "" # Technical Notes: -# - We set apt-get update || true, because for some release (at least odoo:10) +# - We set apt-get update || true, because for some version (at least odoo:10) # the command update fail, because of obsolete postgresql repository. DOCKERFILE_TEMPLATE = """ -FROM odoo:{{ odoo_version['release'] }} +FROM odoo:{{ odoo_version }} MAINTAINER GRAP, Coop It Easy # Set User root for installations @@ -133,7 +132,7 @@ RUN apt-get update || true &&\ xargs apt-get install -y --no-install-recommends - Initial Release - Final Release + Initial Version + Final Version Project Name Analysis Date - {{ ctx.obj["config"]["odoo_versions"][0]["release"] }} - {{ ctx.obj["config"]["odoo_versions"][-1]["release"] }} + {{ ctx.obj["config"]["odoo_versions"][0] }} + {{ ctx.obj["config"]["odoo_versions"][-1] }} {{ ctx.obj["config"]["project_name"] }} {{ current_date }} @@ -230,7 +229,7 @@ ANALYSIS_HTML_TEMPLATE = """   {%- for odoo_version in ctx.obj["config"]["odoo_versions"] -%} - {{ odoo_version["release"] }} + {{ odoo_version }} {% endfor %} @@ -277,8 +276,8 @@ ANALYSIS_HTML_TEMPLATE = """ {{odoo_module.name}} - {% for release in odoo_module.analyse.all_releases %} - {% set module_version = odoo_module.get_module_version(release) %} + {% for version in odoo_module.analyse.all_version %} + {% set module_version = odoo_module.get_module_version(version) %} {% if module_version %} {% set size_text = module_version.get_size_text() %} {% set analysis_text = module_version.get_analysis_text() %} diff --git a/odoo_openupgrade_wizard/tools_odoo.py b/odoo_openupgrade_wizard/tools_odoo.py index 77a1a22..f6e664b 100644 --- a/odoo_openupgrade_wizard/tools_odoo.py +++ b/odoo_openupgrade_wizard/tools_odoo.py @@ -23,8 +23,9 @@ from odoo_openupgrade_wizard.tools_system import get_script_folder def get_odoo_addons_path( ctx, root_path: Path, migration_step: dict, execution_context: str = False ) -> str: - odoo_version = get_odoo_version_from_migration_step(ctx, migration_step) - repo_file = get_odoo_env_path(ctx, odoo_version) / Path("repos.yml") + repo_file = get_odoo_env_path(ctx, migration_step["version"]) / Path( + "repos.yml" + ) base_module_folder = get_base_module_folder(migration_step) stream = open(repo_file, "r") data = yaml.safe_load(stream) @@ -49,37 +50,29 @@ def get_odoo_addons_path( return addons_path -def get_odoo_env_path(ctx, odoo_version: dict) -> Path: - folder_name = "env_%s" % str(odoo_version["release"]).rjust(4, "0") +def get_odoo_env_path(ctx, odoo_version: float) -> Path: + folder_name = "env_%s" % str(odoo_version).rjust(4, "0") return ctx.obj["src_folder_path"] / folder_name -def get_docker_image_tag(ctx, odoo_version: dict) -> str: - """Return a docker image tag, based on project name and odoo release""" +def get_docker_image_tag(ctx, odoo_version: float) -> str: + """Return a docker image tag, based on project name and odoo version""" return "odoo-openupgrade-wizard-image__%s__%s" % ( ctx.obj["config"]["project_name"], - str(odoo_version["release"]).rjust(4, "0"), + str(odoo_version).rjust(4, "0"), ) def get_docker_container_name(ctx, migration_step: dict) -> str: """Return a docker container name, based on project name, - odoo release and migration step""" + odoo version and migration step""" return "odoo-openupgrade-wizard-container__%s__%s__step-%s" % ( ctx.obj["config"]["project_name"], - str(migration_step["release"]).rjust(4, "0"), + str(migration_step["version"]).rjust(4, "0"), str(migration_step["name"]).rjust(2, "0"), ) -def get_odoo_version_from_migration_step(ctx, migration_step: dict) -> dict: - for odoo_version in ctx.obj["config"]["odoo_versions"]: - if odoo_version["release"] == migration_step["release"]: - return odoo_version - # TODO, improve exception - raise Exception - - def generate_odoo_command( ctx, migration_step: dict, @@ -123,8 +116,7 @@ def generate_odoo_config_file( This configuration file is a merge of the odoo.cfg file that can contain custom values, and the values required to run the docker container. """ - odoo_version = get_odoo_version_from_migration_step(ctx, migration_step) - odoo_env_path = get_odoo_env_path(ctx, odoo_version) + odoo_env_path = get_odoo_env_path(ctx, migration_step["version"]) custom_odoo_config_file = odoo_env_path / "odoo.cfg" auto_generated_odoo_config_file = ( @@ -187,10 +179,10 @@ def run_odoo( # Ensure that Postgres container exist get_postgres_container(ctx) logger.info( - "Launching Odoo Container (Release {release}) for {db_text}" + "Launching Odoo Container (Version {version}) for {db_text}" " in {execution_context} mode. Demo Data is {demo_text}" " {stop_text} {init_text} {update_text}".format( - release=migration_step["release"], + version=migration_step["version"], db_text=database and "database '%s'" % database or "any databases", execution_context=execution_context or migration_step["execution_context"], @@ -200,9 +192,8 @@ def run_odoo( update_text=update and " (Update : %s)" % update or "", ) ) - odoo_version = get_odoo_version_from_migration_step(ctx, migration_step) env_path = ctx.obj["env_folder_path"] - odoo_env_path = get_odoo_env_path(ctx, odoo_version) + odoo_env_path = get_odoo_env_path(ctx, migration_step["version"]) log_file = "/env/log/{}____{}.log".format( ctx.obj["log_prefix"], migration_step["complete_name"] ) @@ -227,7 +218,7 @@ def run_odoo( ) links.update({ctx.obj["config"]["postgres_container_name"]: "db"}) return run_container( - get_docker_image_tag(ctx, odoo_version), + get_docker_image_tag(ctx, migration_step["version"]), get_docker_container_name(ctx, migration_step), command=command, ports={ @@ -267,10 +258,9 @@ def execute_click_odoo_python_files( python_files = sorted(python_files) # Prepare data information for docker - odoo_version = get_odoo_version_from_migration_step(ctx, migration_step) links = {ctx.obj["config"]["postgres_container_name"]: "db"} env_path = ctx.obj["env_folder_path"] - odoo_env_path = get_odoo_env_path(ctx, odoo_version) + odoo_env_path = get_odoo_env_path(ctx, migration_step["version"]) # Generate odoo config file log_file = "/env/log/{}____{}__post_migration.log".format( @@ -296,7 +286,7 @@ def execute_click_odoo_python_files( % (migration_step["complete_name"], python_file) ) run_container( - get_docker_image_tag(ctx, odoo_version), + get_docker_image_tag(ctx, migration_step["version"]), get_docker_container_name(ctx, migration_step), command=command, ports={}, diff --git a/odoo_openupgrade_wizard/tools_odoo_module.py b/odoo_openupgrade_wizard/tools_odoo_module.py index 19c377b..57495a3 100644 --- a/odoo_openupgrade_wizard/tools_odoo_module.py +++ b/odoo_openupgrade_wizard/tools_odoo_module.py @@ -21,29 +21,27 @@ from odoo_openupgrade_wizard.tools_odoo import ( class Analysis(object): def __init__(self, ctx): self.modules = [] - self.initial_release = ctx.obj["config"]["odoo_versions"][0]["release"] - self.final_release = ctx.obj["config"]["odoo_versions"][-1]["release"] - self.all_releases = [ - x["release"] for x in ctx.obj["config"]["odoo_versions"] - ] + self.initial_version = ctx.obj["config"]["odoo_versions"][0] + self.final_version = ctx.obj["config"]["odoo_versions"][-1] + self.all_versions = [x for x in ctx.obj["config"]["odoo_versions"]] def analyse_module_version(self, ctx, module_list): - self._generate_module_version_first_release(ctx, module_list) + self._generate_module_version_first_version(ctx, module_list) - for count in range(len(self.all_releases) - 1): - previous_release = self.all_releases[count] - current_release = self.all_releases[count + 1] - self._generate_module_version_next_release( - ctx, previous_release, current_release + for count in range(len(self.all_versions) - 1): + previous_version = self.all_versions[count] + current_version = self.all_versions[count + 1] + self._generate_module_version_next_version( + ctx, previous_version, current_version ) def analyse_openupgrade_state(self, ctx): logger.info("Parsing openupgrade module coverage for each migration.") coverage_analysis = {} - for release in self.all_releases[1:]: - coverage_analysis[release] = {} - relative_path = get_coverage_relative_path({"release": release}) - env_folder_path = get_odoo_env_path(ctx, {"release": release}) + for version in self.all_versions[1:]: + coverage_analysis[version] = {} + relative_path = get_coverage_relative_path(version) + env_folder_path = get_odoo_env_path(ctx, version) coverage_path = env_folder_path / relative_path with open(coverage_path) as f: lines = f.readlines() @@ -55,11 +53,11 @@ class Analysis(object): ) splited_line = [x.strip() for x in clean_line.split("|") if x] if len(splited_line) == 2: - coverage_analysis[release][splited_line[0]] = splited_line[ + coverage_analysis[version][splited_line[0]] = splited_line[ 1 ] if len(splited_line) == 3: - coverage_analysis[release][splited_line[0]] = ( + coverage_analysis[version][splited_line[0]] = ( splited_line[1] + " " + splited_line[2] ).strip() elif len(splited_line) > 3: @@ -74,16 +72,16 @@ class Analysis(object): for module_version in list(odoo_module.module_versions.values()): module_version.analyse_openupgrade_state(coverage_analysis) - for release in self.all_releases[1:]: - odoo_env_path = get_odoo_env_path(ctx, {"release": release}) + for version in self.all_versions[1:]: + odoo_env_path = get_odoo_env_path(ctx, version) openupgrade_analysis_files = get_openupgrade_analysis_files( - odoo_env_path, release + odoo_env_path, version ) openupgrade_analysis_files = openupgrade_analysis_files for odoo_module in filter( lambda x: x.module_type == "odoo", self.modules ): - module_version = odoo_module.get_module_version(release) + module_version = odoo_module.get_module_version(version) if module_version: module_version.analyse_openupgrade_work( openupgrade_analysis_files @@ -94,7 +92,7 @@ class Analysis(object): lambda x: x.module_type != "odoo", self.modules ): last_module_version = odoo_module.module_versions.get( - self.final_release, False + self.final_version, False ) if ( @@ -110,17 +108,17 @@ class Analysis(object): for module_version in odoo_module.module_versions.values(): module_version.estimate_workload(ctx) - def _generate_module_version_first_release(self, ctx, module_list): + def _generate_module_version_first_version(self, ctx, module_list): not_found_modules = [] logger.info( - "Analyse version %s. (First Release)" % self.initial_release + "Analyse version %s. (First version)" % self.initial_version ) # Instanciate a new odoo_module for module_name in module_list: addon_path = OdooModule.get_addon_path( - ctx, module_name, self.initial_release + ctx, module_name, self.initial_version ) if addon_path: repository_name = OdooModule.get_repository_name(addon_path) @@ -129,54 +127,54 @@ class Analysis(object): not in self.modules ): logger.debug( - "Discovering module '%s' in %s for release %s" - % (module_name, repository_name, self.initial_release) + "Discovering module '%s' in %s for version %s" + % (module_name, repository_name, self.initial_version) ) new_odoo_module = OdooModule( ctx, self, module_name, repository_name ) new_module_version = OdooModuleVersion( - self.initial_release, new_odoo_module, addon_path + self.initial_version, new_odoo_module, addon_path ) new_odoo_module.module_versions.update( - {self.initial_release: new_module_version} + {self.initial_version: new_module_version} ) self.modules.append(new_odoo_module) else: logger.error( - "Module %s not found for release %s." - % (module_name, self.initial_release) + "Module %s not found for version %s." + % (module_name, self.initial_version) ) not_found_modules.append(module_name) if not_found_modules: raise ValueError( - "The modules %s have not been found in the release %s." + "The modules %s have not been found in the version %s." " Analyse can not be done. Please update your repos.yml" - " of your initial release to add repositories that" + " of your initial version to add repositories that" " include the modules, then run again the command." - % (",".join(not_found_modules), self.initial_release) + % (",".join(not_found_modules), self.initial_version) ) - def _generate_module_version_next_release( - self, ctx, previous_release, current_release + def _generate_module_version_next_version( + self, ctx, previous_version, current_version ): logger.info( "Analyse change between %s and %s" - % (previous_release, current_release) + % (previous_version, current_version) ) - # Get changes between the two releases + # Get changes between the two versions ( apriori_module_name, apriori_relative_path, - ) = get_apriori_file_relative_path({"release": current_release}) + ) = get_apriori_file_relative_path(current_version) apriori_module_path = OdooModule.get_addon_path( - ctx, apriori_module_name, current_release + ctx, apriori_module_name, current_version ) if not apriori_module_path: raise ValueError( - "Unable to find the path of the module %s for the release %s" - % (apriori_module_name, current_release) + "Unable to find the path of the module %s for the version %s" + % (apriori_module_name, current_version) ) apriori_absolute_path = ( apriori_module_path @@ -202,8 +200,8 @@ class Analysis(object): logger.debug( "%s -> %s : %s renamed into %s" % ( - previous_release, - current_release, + previous_version, + current_version, odoo_module.name, new_module_name, ) @@ -214,8 +212,8 @@ class Analysis(object): logger.debug( "%s -> %s : %s merged into %s" % ( - previous_release, - current_release, + previous_version, + current_version, odoo_module.name, new_module_name, ) @@ -225,13 +223,13 @@ class Analysis(object): if state and new_module_name != odoo_module.name: # Ensure that the module exists in self.modules new_addon_path = OdooModule.get_addon_path( - ctx, new_module_name, current_release + ctx, new_module_name, current_version ) if not new_addon_path: raise ValueError( - "The module %s has not been found in the release %s." + "The module %s has not been found in the version %s." " Analyse can not be done." - % (new_module_name, current_release) + % (new_module_name, current_version) ) else: new_repository_name = OdooModule.get_repository_name( @@ -242,11 +240,11 @@ class Analysis(object): not in self.modules ): logger.debug( - "Discovering module '%s' in %s for release %s" + "Discovering module '%s' in %s for version %s" % ( new_module_name, new_repository_name, - current_release, + current_version, ) ) new_odoo_module = OdooModule( @@ -255,19 +253,19 @@ class Analysis(object): self.modules.append(new_odoo_module) new_odoo_module.module_versions.update( { - current_release: OdooModuleVersion( - current_release, + current_version: OdooModuleVersion( + current_version, new_odoo_module, new_addon_path, ) } ) - # Get the previous release of the module + # Get the previous version of the module previous_module_version = odoo_module.get_module_version( - previous_release + previous_version ) - # if the previous release has been renamed or merged + # if the previous version has been renamed or merged # the loss is normal if previous_module_version and previous_module_version.state in [ "merged", @@ -277,12 +275,12 @@ class Analysis(object): state = "normal_loss" new_addon_path = OdooModule.get_addon_path( - ctx, odoo_module.name, current_release + ctx, odoo_module.name, current_version ) odoo_module.module_versions.update( { - current_release: OdooModuleVersion( - current_release, + current_version: OdooModuleVersion( + current_version, odoo_module, new_addon_path, state=state, @@ -336,23 +334,23 @@ class OdooModule(object): else: self.module_type = "custom" - def get_module_version(self, current_release): - res = self.module_versions.get(current_release, False) + def get_module_version(self, current_version): + res = self.module_versions.get(current_version, False) return res @classmethod - def get_addon_path(cls, ctx, module_name, current_release): - """Search the module in all the addons path of the current release + def get_addon_path(cls, ctx, module_name, current_version): + """Search the module in all the addons path of a given version and return the addon path of the module, or False if not found. For exemple find_repository(ctx, 'web_responsive', 12.0) '/PATH_TO_LOCAL_ENV/src/OCA/web' """ # Try to find the repository that contains the module - main_path = get_odoo_env_path(ctx, {"release": current_release}) + main_path = get_odoo_env_path(ctx, current_version) addons_path = get_odoo_addons_path( ctx, main_path, - {"release": current_release, "execution_context": "openupgrade"}, + {"version": current_version, "execution_context": "openupgrade"}, ) for addon_path in addons_path: if (addon_path / module_name).exists(): @@ -427,13 +425,13 @@ class OdooModuleVersion(object): def __init__( self, - release, + version, odoo_module, addon_path, state=False, target_module=False, ): - self.release = release + self.version = version self.odoo_module = odoo_module self.addon_path = addon_path self.state = state @@ -471,8 +469,8 @@ class OdooModuleVersion(object): return if self.odoo_module.module_type == "odoo": - if self.release == self.odoo_module.analyse.initial_release: - # No work to do for the initial release + if self.version == self.odoo_module.analyse.initial_version: + # No work to do for the initial version return if self.openupgrade_state and ( self.openupgrade_state.lower().startswith("done") @@ -498,8 +496,8 @@ class OdooModuleVersion(object): ) # OCA / Custom Module - if self.release != self.odoo_module.analyse.final_release: - # No need to work for intermediate release (in theory ;-)) + if self.version != self.odoo_module.analyse.final_version: + # No need to work for intermediate version (in theory ;-)) return if self.addon_path: @@ -510,8 +508,8 @@ class OdooModuleVersion(object): self.workload = ( # Minimal port time port_minimal_time - # Add time per release - + (self.release - previous_module_version.release) + # Add time per version + + (self.version - previous_module_version.version) * port_per_version # Add python time + (port_per_python_line_time * previous_module_version.python_code) @@ -558,14 +556,14 @@ class OdooModuleVersion(object): self.javascript_code += file_res.code def analyse_openupgrade_state(self, coverage_analysis): - if self.release == self.odoo_module.analyse.initial_release: + if self.version == self.odoo_module.analyse.initial_version: return - self.openupgrade_state = coverage_analysis[self.release].get( + self.openupgrade_state = coverage_analysis[self.version].get( self.odoo_module.name, False ) def analyse_openupgrade_work(self, analysis_files): - if self.release == self.odoo_module.analyse.initial_release: + if self.version == self.odoo_module.analyse.initial_version: return analysis_file = analysis_files.get(self.odoo_module.name, False) @@ -641,7 +639,7 @@ class OdooModuleVersion(object): if self.addon_path: if ( self.odoo_module.module_type == "odoo" - and self.release != self.odoo_module.analyse.initial_release + and self.version != self.odoo_module.analyse.initial_version ): if self.openupgrade_state and ( self.openupgrade_state.lower().startswith("done") @@ -654,7 +652,7 @@ class OdooModuleVersion(object): return "orange" return "lightgreen" else: - # The module doesn't exist in the current release + # The module doesn't exist in the current version if self.state in ["merged", "renamed", "normal_loss"]: # Normal case, the previous version has been renamed # or merged @@ -664,7 +662,7 @@ class OdooModuleVersion(object): # A core module disappeared and has not been merged # or renamed return "red" - elif self.release != self.odoo_module.analyse.final_release: + elif self.version != self.odoo_module.analyse.final_version: return "lightgray" else: return "orange" @@ -673,7 +671,7 @@ class OdooModuleVersion(object): if self.addon_path: if ( self.odoo_module.module_type == "odoo" - and self.release != self.odoo_module.analyse.initial_release + and self.version != self.odoo_module.analyse.initial_version ): if self.openupgrade_state.lower().startswith( "done" @@ -696,10 +694,10 @@ class OdooModuleVersion(object): # A core module disappeared and has not been merged # or renamed return "Module lost" - elif self.release != self.odoo_module.analyse.final_release: + elif self.version != self.odoo_module.analyse.final_version: return "Unported" else: return ( "To port from %s" - % self.get_last_existing_version().release + % self.get_last_existing_version().version ) diff --git a/tests/cli_01_init_test.py b/tests/cli_01_init_test.py index 8113cf0..416847d 100644 --- a/tests/cli_01_init_test.py +++ b/tests/cli_01_init_test.py @@ -13,8 +13,8 @@ def test_cli_init(): "--log-level=DEBUG", "init", "--project-name=test-cli", - "--initial-release=13.0", - "--final-release=14.0", + "--initial-version=13.0", + "--final-version=14.0", "--extra-repository=" "OCA/web,OCA/server-tools,OCA/bank-statement-import", ] diff --git a/tests/cli_03_docker_build_test.py b/tests/cli_03_docker_build_test.py index e0b026b..791788b 100644 --- a/tests/cli_03_docker_build_test.py +++ b/tests/cli_03_docker_build_test.py @@ -9,7 +9,7 @@ def test_cli_docker_build(): [ "--log-level=DEBUG", "docker-build", - "--releases=13.0,14.0", + "--versions=13.0,14.0", ] ) diff --git a/tests/cli_21_generate_module_analysis_test.py b/tests/cli_21_generate_module_analysis_test.py index 89afbb7..a20624f 100644 --- a/tests/cli_21_generate_module_analysis_test.py +++ b/tests/cli_21_generate_module_analysis_test.py @@ -15,7 +15,7 @@ def test_cli_generate_module_analysis(): ctx = build_ctx_from_config_file() # identify main analysis file of openupgrade - analysis_file_path = get_odoo_env_path(ctx, {"release": 14.0}) / Path( + analysis_file_path = get_odoo_env_path(ctx, 14.0) / Path( "src/openupgrade/openupgrade_scripts/scripts" "/base/14.0.1.3/upgrade_general_log.txt" ) diff --git a/tests/data/output_expected/config.yml b/tests/data/output_expected/config.yml index 6ebcf2e..a986b50 100644 --- a/tests/data/output_expected/config.yml +++ b/tests/data/output_expected/config.yml @@ -1,4 +1,3 @@ - project_name: test-cli postgres_image_name: postgres:13 @@ -9,26 +8,22 @@ odoo_default_country_code: FR odoo_versions: - - - release: 13.0 - - - release: 14.0 - + - 13.0 + - 14.0 migration_steps: - - name: 1 - release: 13.0 + version: 13.0 execution_context: regular complete_name: step_01__update__13.0 - name: 2 - release: 14.0 + version: 14.0 execution_context: openupgrade complete_name: step_02__upgrade__14.0 - name: 3 - release: 14.0 + version: 14.0 execution_context: regular complete_name: step_03__update__14.0