Merge branch 'dev-7-harmonization-revision-release-2' into 'main'

[REF] merge version and release concept and simplify version settings

See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!7
This commit is contained in:
LE GAL SYLVAIN 2022-06-21 22:32:34 +00:00
commit e27e49e209
14 changed files with 246 additions and 240 deletions

View File

@ -47,8 +47,8 @@ in ``DEVELOP.md`` file.)
``` ```
odoo-openupgrade-wizard init\ odoo-openupgrade-wizard init\
--initial-release=10.0\ --initial-version=10.0\
--final-release=12.0\ --final-version=12.0\
--project-name=my-customer-10-12\ --project-name=my-customer-10-12\
--extra-repository=OCA/web,OCA/server-tools --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** **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** **Optional arguments**
* if you want to (re)build an image for some given releases, you can provide * if you want to (re)build an image for some given versions, you can provide
an extra parameter: ``--releases 10.0,12.0`` an extra parameter: ``--versions 10.0,12.0``
**Note** **Note**
@ -256,8 +256,8 @@ odoo-openupgrade-wizard upgrade\
--database DB_NAME --database DB_NAME
``` ```
Realize an upgrade of the database from the initial release to Realize an upgrade of the database from the initial version to
the final release, following the different steps. the final version, following the different steps.
For each step, it will : For each step, it will :

View File

@ -3,7 +3,7 @@ from loguru import logger
from odoo_openupgrade_wizard.cli_options import ( from odoo_openupgrade_wizard.cli_options import (
get_odoo_versions_from_options, 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_docker import build_image, pull_image
from odoo_openupgrade_wizard.tools_odoo import ( from odoo_openupgrade_wizard.tools_odoo import (
@ -13,19 +13,19 @@ from odoo_openupgrade_wizard.tools_odoo import (
@click.command() @click.command()
@releases_options @versions_options
@click.pass_context @click.pass_context
def docker_build(ctx, releases): def docker_build(ctx, versions):
"""Build Odoo Docker Images. (One image per release)""" """Build Odoo Docker Images. (One image per version)"""
# Pull DB image # Pull DB image
pull_image(ctx.obj["config"]["postgres_image_name"]) pull_image(ctx.obj["config"]["postgres_image_name"])
# Build images for each odoo version # 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( logger.info(
"Building Odoo docker image for release '%s'. " "Building Odoo docker image for version '%s'. "
"This can take a while..." % (odoo_version["release"]) "This can take a while..." % (odoo_version)
) )
image = build_image( image = build_image(
get_odoo_env_path(ctx, odoo_version), get_odoo_env_path(ctx, odoo_version),

View File

@ -48,11 +48,11 @@ def generate_module_analysis(ctx, step, database, modules):
initial_database = "%s_%s" % ( initial_database = "%s_%s" % (
database, database,
str(initial_step["release"]).replace(".", ""), str(initial_step["version"]).replace(".", ""),
) )
final_database = "%s_%s" % ( final_database = "%s_%s" % (
database, database,
str(final_step["release"]).replace(".", ""), str(final_step["version"]).replace(".", ""),
) )
modules = modules and modules.split(",") or [] 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 # group to make possible to write analysis files
# for docker container user # for docker container user
ensure_folder_writable( 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( generate_analysis_files(

View File

@ -2,14 +2,14 @@ import click
from odoo_openupgrade_wizard.cli_options import ( from odoo_openupgrade_wizard.cli_options import (
get_odoo_versions_from_options, 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_odoo import get_odoo_env_path
from odoo_openupgrade_wizard.tools_system import git_aggregate from odoo_openupgrade_wizard.tools_system import git_aggregate
@click.command() @click.command()
@releases_options @versions_options
@click.option( @click.option(
"-j", "-j",
"--jobs", "--jobs",
@ -19,10 +19,10 @@ from odoo_openupgrade_wizard.tools_system import git_aggregate
" reasonably set to 10 by default.", " reasonably set to 10 by default.",
) )
@click.pass_context @click.pass_context
def get_code(ctx, releases, jobs): def get_code(ctx, versions, jobs):
"""Get code by running gitaggregate command for each release""" """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) folder_path = get_odoo_env_path(ctx, odoo_version)
repo_file_path = folder_path / "repos.yml" repo_file_path = folder_path / "repos.yml"
git_aggregate(folder_path, repo_file_path, jobs) git_aggregate(folder_path, repo_file_path, jobs)

View File

@ -5,7 +5,9 @@ import click
from odoo_openupgrade_wizard import templates from odoo_openupgrade_wizard import templates
from odoo_openupgrade_wizard.configuration_version_dependant import ( from odoo_openupgrade_wizard.configuration_version_dependant import (
get_odoo_versions, 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_odoo import get_odoo_env_path
from odoo_openupgrade_wizard.tools_system import ( from odoo_openupgrade_wizard.tools_system import (
@ -26,16 +28,16 @@ from odoo_openupgrade_wizard.tools_system import (
" name the odoo docker images.", " name the odoo docker images.",
) )
@click.option( @click.option(
"--initial-release", "--initial-version",
required=True, required=True,
prompt=True, prompt=True,
type=click.Choice(get_release_options("initial")), type=click.Choice(get_version_options("initial")),
) )
@click.option( @click.option(
"--final-release", "--final-version",
required=True, required=True,
prompt=True, prompt=True,
type=click.Choice(get_release_options("final")), type=click.Choice(get_version_options("final")),
) )
@click.option( @click.option(
"--extra-repository", "--extra-repository",
@ -46,10 +48,10 @@ from odoo_openupgrade_wizard.tools_system import (
) )
@click.pass_context @click.pass_context
def init( 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 """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 # Handle arguments
@ -65,7 +67,7 @@ def init(
# 1. Compute Odoo versions # 1. Compute Odoo versions
odoo_versions = get_odoo_versions( odoo_versions = get_odoo_versions(
float(initial_release), float(final_release) float(initial_version), float(final_version)
) )
# 2. Compute Migration Steps # 2. Compute Migration Steps
@ -75,9 +77,8 @@ def init(
{ {
"name": 1, "name": 1,
"execution_context": "regular", "execution_context": "regular",
"release": odoo_versions[0]["release"], "version": odoo_versions[0],
"complete_name": "step_01__update__%s" "complete_name": "step_01__update__%s" % (odoo_versions[0]),
% (odoo_versions[0]["release"]),
} }
] ]
@ -88,9 +89,9 @@ def init(
{ {
"name": step_nbr, "name": step_nbr,
"execution_context": "openupgrade", "execution_context": "openupgrade",
"release": odoo_version["release"], "version": odoo_version,
"complete_name": "step_%s__upgrade__%s" "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 step_nbr += 1
@ -101,9 +102,9 @@ def init(
{ {
"name": step_nbr, "name": step_nbr,
"execution_context": "regular", "execution_context": "regular",
"release": odoo_versions[-1]["release"], "version": odoo_versions[-1],
"complete_name": "step_%s__update__%s" "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( ensure_file_exists_from_template(
path_version / Path("python_requirements.txt"), path_version / Path("python_requirements.txt"),
templates.PYTHON_REQUIREMENTS_TXT_TEMPLATE, templates.PYTHON_REQUIREMENTS_TXT_TEMPLATE,
python_libraries=odoo_version["python_libraries"], python_libraries=get_python_libraries(odoo_version),
) )
# Create debian requirements file # Create debian requirements file
@ -182,6 +183,7 @@ def init(
path_version / Path("Dockerfile"), path_version / Path("Dockerfile"),
templates.DOCKERFILE_TEMPLATE, templates.DOCKERFILE_TEMPLATE,
odoo_version=odoo_version, odoo_version=odoo_version,
python_major_version=get_python_major_version(odoo_version),
) )
# Create 'src' folder that will contain all the odoo code # Create 'src' folder that will contain all the odoo code

View File

@ -1,14 +1,14 @@
import click import click
def releases_options(function): def versions_options(function):
function = click.option( function = click.option(
"-r", "-v",
"--releases", "--versions",
type=str, 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." " 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", " of the project",
)(function) )(function)
return function return function
@ -66,15 +66,15 @@ def database_option_required(function):
return 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"] return ctx.obj["config"]["odoo_versions"]
else: else:
odoo_versions = [] 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"]: 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) odoo_versions.append(odoo_version)
return odoo_versions return odoo_versions

View File

@ -4,27 +4,27 @@ from loguru import logger
_ODOO_VERSION_TEMPLATES = [ _ODOO_VERSION_TEMPLATES = [
{ {
"release": 8.0, "version": 8.0,
"python_major_version": "python2", "python_major_version": "python2",
"python_libraries": [], "python_libraries": [],
}, },
{ {
"release": 9.0, "version": 9.0,
"python_major_version": "python2", "python_major_version": "python2",
"python_libraries": ["openupgradelib==2.0.0"], "python_libraries": ["openupgradelib==2.0.0"],
}, },
{ {
"release": 10.0, "version": 10.0,
"python_major_version": "python2", "python_major_version": "python2",
"python_libraries": ["openupgradelib==2.0.0"], "python_libraries": ["openupgradelib==2.0.0"],
}, },
{ {
"release": 11.0, "version": 11.0,
"python_major_version": "python3", "python_major_version": "python3",
"python_libraries": ["openupgradelib==2.0.0"], "python_libraries": ["openupgradelib==2.0.0"],
}, },
{ {
"release": 12.0, "version": 12.0,
"python_major_version": "python3", "python_major_version": "python3",
"python_libraries": [ "python_libraries": [
"git+https://github.com/grap/openupgradelib.git" "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_major_version": "python3",
"python_libraries": ["openupgradelib"], "python_libraries": ["openupgradelib"],
}, },
{ {
"release": 14.0, "version": 14.0,
"python_major_version": "python3", "python_major_version": "python3",
"python_libraries": ["openupgradelib"], "python_libraries": ["openupgradelib"],
}, },
{ {
"release": 15.0, "version": 15.0,
"python_major_version": "python3", "python_major_version": "python3",
"python_libraries": ["openupgradelib"], "python_libraries": ["openupgradelib"],
}, },
] ]
def get_release_options(mode: str) -> list: def get_version_template(version: float) -> dict:
"""Get options available for release click argument. """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: Arguments:
mode: Possible value 'initial', 'final' mode: Possible value 'initial', 'final'
Return: Return:
@ -58,32 +80,32 @@ def get_release_options(mode: str) -> list:
Exemple: Exemple:
['9.0', '10.0', '11.0'] ['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": if mode == "initial":
releases_list = releases_list[:-1] version_options = version_options[:-1]
if mode == "final": if mode == "final":
releases_list = releases_list[1:] version_options = version_options[1:]
return releases_list return version_options
def get_odoo_versions(initial_release: float, final_release: float) -> list: def get_odoo_versions(initial_version: float, final_version: float) -> list:
"""Return a list of odoo versions from the initial release to the final """Return a list of odoo versions from the initial version to the final
release version
""" """
result = [] result = []
for version_template in _ODOO_VERSION_TEMPLATES: for version_template in _ODOO_VERSION_TEMPLATES:
if ( if (
version_template["release"] >= initial_release version_template["version"] >= initial_version
and version_template["release"] <= final_release and version_template["version"] <= final_version
): ):
result.append(version_template) result.append(version_template["version"])
return result return result
def get_odoo_run_command(migration_step: dict) -> str: def get_odoo_run_command(migration_step: dict) -> str:
"""Return the name of the command to execute, depending on the migration """Return the name of the command to execute, depending on the migration
step. (odoo-bin, odoo.py, etc...)""" step. (odoo-bin, odoo.py, etc...)"""
if migration_step["release"] >= 10.0: if migration_step["version"] >= 10.0:
return "odoo-bin" return "odoo-bin"
return "odoo.py" return "odoo.py"
@ -97,13 +119,13 @@ def get_odoo_folder(
if execution_context == "regular": if execution_context == "regular":
return "src/odoo" return "src/odoo"
elif execution_context == "openupgrade" and migration_step["release"] < 14: elif execution_context == "openupgrade" and migration_step["version"] < 14:
return "src/openupgrade" return "src/openupgrade"
if migration_step["execution_context"] == "regular": if migration_step["execution_context"] == "regular":
return "src/odoo" return "src/odoo"
if migration_step["release"] >= 14.0: if migration_step["version"] >= 14.0:
return "src/odoo" return "src/odoo"
return "src/openupgrade" return "src/openupgrade"
@ -112,7 +134,7 @@ def get_odoo_folder(
def get_base_module_folder(migration_step: dict) -> str: def get_base_module_folder(migration_step: dict) -> str:
"""return the name of the folder (odoo, openerp, etc...) """return the name of the folder (odoo, openerp, etc...)
where the 'base' module is, depending on the migration_step""" 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 "odoo"
return "openerp" return "openerp"
@ -126,13 +148,13 @@ def skip_addon_path(migration_step: dict, path: Path) -> bool:
return ( return (
str(path).endswith("/src/odoo") str(path).endswith("/src/odoo")
or str(path).endswith("src/openupgrade") 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: def get_server_wide_modules_upgrade(migration_step: dict) -> list:
"""return a list of modules to load, depending on the migration step.""" """return a list of modules to load, depending on the migration step."""
if ( if (
migration_step["release"] >= 14.0 migration_step["version"] >= 14.0
and migration_step["execution_context"] == "openupgrade" and migration_step["execution_context"] == "openupgrade"
): ):
return ["openupgrade_framework"] 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: def get_upgrade_analysis_module(migration_step: dict) -> str:
"""return the upgrade_analysis module name""" """return the upgrade_analysis module name"""
if migration_step["release"] >= 14.0: if migration_step["version"] >= 14.0:
# (Module in OCA/server-tools) # (Module in OCA/server-tools)
return "upgrade_analysis" return "upgrade_analysis"
@ -152,10 +174,10 @@ def get_upgrade_analysis_module(migration_step: dict) -> str:
def generate_records(odoo_instance, migration_step: dict): def generate_records(odoo_instance, migration_step: dict):
logger.info( logger.info(
"Generate Records in release %s ..." "Generate Records in version %s ..."
" (It can take a while)" % (migration_step["release"]) " (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( wizard = odoo_instance.browse_by_create(
"openupgrade.generate.records.wizard", {} "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): 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 # TODO, improve that algorithm, if possible
modules = odoo_instance.browse_by_search( modules = odoo_instance.browse_by_search(
"ir.module.module", "ir.module.module",
@ -195,14 +217,14 @@ def generate_analysis_files(
" the modules installed on %s ..." % (initial_database) " the modules installed on %s ..." % (initial_database)
) )
proxy_vals = { proxy_vals = {
"name": "Proxy to Previous Release", "name": "Proxy to Previous version",
"server": initial_odoo_host, "server": initial_odoo_host,
"port": "8069", "port": "8069",
"database": initial_database, "database": initial_database,
"username": "admin", "username": "admin",
"password": "admin", "password": "admin",
} }
if final_step["release"] < 14.0: if final_step["version"] < 14.0:
logger.info("> Create proxy ...") logger.info("> Create proxy ...")
proxy = final_odoo_instance.browse_by_create( proxy = final_odoo_instance.browse_by_create(
"openupgrade.comparison.config", proxy_vals "openupgrade.comparison.config", proxy_vals
@ -237,44 +259,44 @@ def generate_analysis_files(
analysis.analyze() 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 """Return the module name and the relative file path of
the apriori.py file that contains all the rename and the apriori.py file that contains all the rename and
the merge information for a given upgrade.""" the merge information for a given upgrade."""
if migration_step["release"] < 14.0: if version < 14.0:
return ("openupgrade_records", Path("lib/apriori.py")) return ("openupgrade_records", Path("lib/apriori.py"))
else: else:
return ("openupgrade_scripts", Path("apriori.py")) 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.""" """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") 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") base_path = Path("src/openupgrade/odoo/openupgrade/doc/source")
else: else:
base_path = Path("src/openupgrade/docsource") base_path = Path("src/openupgrade/docsource")
previous_release = migration_step["release"] - 1 previous_version = version - 1
return base_path / Path( return base_path / Path(
"modules%s-%s.rst" "modules%s-%s.rst"
% ( % (
("%.1f" % previous_release).replace(".", ""), ("%.1f" % previous_version).replace(".", ""),
("%.1f" % migration_step["release"]).replace(".", ""), ("%.1f" % version).replace(".", ""),
) )
) )
def get_openupgrade_analysis_files( def get_openupgrade_analysis_files(
odoo_env_path: Path, release: float odoo_env_path: Path, version: float
) -> dict: ) -> dict:
"""return a dictionnary of module_name : path, """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 and and path is the path of the migration_analysis.txt file
of the module""" of the module"""
result = {} result = {}
if release < 14.0: if version < 14.0:
base_name = "openupgrade_analysis.txt" base_name = "openupgrade_analysis.txt"
else: else:
base_name = "upgrade_analysis.txt" base_name = "upgrade_analysis.txt"
@ -286,7 +308,7 @@ def get_openupgrade_analysis_files(
] ]
for file in 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. # 14+ module can have migrations folder.
if file.parent.parent.name == "migrations": if file.parent.parent.name == "migrations":
module_name = file.parent.parent.parent.name module_name = file.parent.parent.parent.name
@ -294,6 +316,6 @@ def get_openupgrade_analysis_files(
module_name = file.parent.parent.name module_name = file.parent.parent.name
result[module_name] = file result[module_name] = file
logger.debug( logger.debug(
"Release %s : %d analysis files found." % (release, len(result)) "Version %s : %d analysis files found." % (version, len(result))
) )
return result return result

View File

@ -1,5 +1,4 @@
CONFIG_YML_TEMPLATE = """ CONFIG_YML_TEMPLATE = """project_name: {{ project_name }}
project_name: {{ project_name }}
postgres_image_name: postgres:13 postgres_image_name: postgres:13
postgres_container_name: {{project_name}}-db postgres_container_name: {{project_name}}-db
@ -9,14 +8,14 @@ odoo_default_country_code: FR
odoo_versions: odoo_versions:
{% for odoo_version in odoo_versions %} {%- for odoo_version in odoo_versions %}
- release: {{ odoo_version['release'] }} - {{ odoo_version }}
{% endfor %} {%- endfor %}
migration_steps: migration_steps:
{% for step in steps %} {%- for step in steps %}
- name: {{ step['name'] }} - name: {{ step['name'] }}
release: {{ step['release'] }} version: {{ step['version'] }}
execution_context: {{ step['execution_context'] }} execution_context: {{ step['execution_context'] }}
complete_name: {{ step['complete_name'] }} complete_name: {{ step['complete_name'] }}
{% endfor %} {% endfor %}
@ -62,9 +61,9 @@ REPO_YML_TEMPLATE = """
depth: 1 depth: 1
remotes: remotes:
odoo: https://github.com/odoo/odoo odoo: https://github.com/odoo/odoo
target: odoo {{ odoo_version['release'] }}-target target: odoo {{ odoo_version }}-target
merges: merges:
- odoo {{ odoo_version['release'] }} - odoo {{ odoo_version }}
############################################################################## ##############################################################################
## OpenUpgrade Repository ## OpenUpgrade Repository
@ -75,9 +74,9 @@ REPO_YML_TEMPLATE = """
depth: 1 depth: 1
remotes: remotes:
OCA: https://github.com/OCA/OpenUpgrade OCA: https://github.com/OCA/OpenUpgrade
target: OCA {{ odoo_version['release'] }}-target target: OCA {{ odoo_version }}-target
merges: merges:
- OCA {{ odoo_version['release'] }} - OCA {{ odoo_version }}
{% for org_name, repo_list in orgs.items() %} {% for org_name, repo_list in orgs.items() %}
############################################################################## ##############################################################################
@ -89,9 +88,9 @@ REPO_YML_TEMPLATE = """
depth: 1 depth: 1
remotes: remotes:
{{ org_name }}: https://github.com/{{ org_name }}/{{ repo }} {{ org_name }}: https://github.com/{{ org_name }}/{{ repo }}
target: {{ org_name }} {{ odoo_version['release'] }}-target target: {{ org_name }} {{ odoo_version }}-target
merges: merges:
- {{ org_name }} {{ odoo_version['release'] }} - {{ org_name }} {{ odoo_version }}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
@ -113,10 +112,10 @@ ODOO_CONFIG_TEMPLATE = ""
# Technical Notes: # 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. # the command update fail, because of obsolete postgresql repository.
DOCKERFILE_TEMPLATE = """ DOCKERFILE_TEMPLATE = """
FROM odoo:{{ odoo_version['release'] }} FROM odoo:{{ odoo_version }}
MAINTAINER GRAP, Coop It Easy MAINTAINER GRAP, Coop It Easy
# Set User root for installations # Set User root for installations
@ -133,7 +132,7 @@ RUN apt-get update || true &&\
xargs apt-get install -y --no-install-recommends <debian_requirements.txt xargs apt-get install -y --no-install-recommends <debian_requirements.txt
# 3. Install extra Python librairies # 3. Install extra Python librairies
RUN {{ odoo_version["python_major_version"] }}\ RUN {{ python_major_version }}\
-m pip install -r python_requirements.txt -m pip install -r python_requirements.txt
# Reset to odoo user to run the container # Reset to odoo user to run the container
@ -173,16 +172,16 @@ ANALYSIS_HTML_TEMPLATE = """
<table border="1" width="100%"> <table border="1" width="100%">
<thead> <thead>
<tr> <tr>
<th>Initial Release</th> <th>Initial Version</th>
<th>Final Release</th> <th>Final Version</th>
<th>Project Name</th> <th>Project Name</th>
<th>Analysis Date</th> <th>Analysis Date</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>{{ ctx.obj["config"]["odoo_versions"][0]["release"] }}</td> <td>{{ ctx.obj["config"]["odoo_versions"][0] }}</td>
<td>{{ ctx.obj["config"]["odoo_versions"][-1]["release"] }}</td> <td>{{ ctx.obj["config"]["odoo_versions"][-1] }}</td>
<td>{{ ctx.obj["config"]["project_name"] }}</td> <td>{{ ctx.obj["config"]["project_name"] }}</td>
<td>{{ current_date }}</td> <td>{{ current_date }}</td>
</tr> </tr>
@ -230,7 +229,7 @@ ANALYSIS_HTML_TEMPLATE = """
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
{%- for odoo_version in ctx.obj["config"]["odoo_versions"] -%} {%- for odoo_version in ctx.obj["config"]["odoo_versions"] -%}
<th>{{ odoo_version["release"] }}</th> <th>{{ odoo_version }}</th>
{% endfor %} {% endfor %}
</tr> </tr>
@ -277,8 +276,8 @@ ANALYSIS_HTML_TEMPLATE = """
<tr> <tr>
<td>{{odoo_module.name}} <td>{{odoo_module.name}}
</td> </td>
{% for release in odoo_module.analyse.all_releases %} {% for version in odoo_module.analyse.all_version %}
{% set module_version = odoo_module.get_module_version(release) %} {% set module_version = odoo_module.get_module_version(version) %}
{% if module_version %} {% if module_version %}
{% set size_text = module_version.get_size_text() %} {% set size_text = module_version.get_size_text() %}
{% set analysis_text = module_version.get_analysis_text() %} {% set analysis_text = module_version.get_analysis_text() %}

View File

@ -23,8 +23,9 @@ from odoo_openupgrade_wizard.tools_system import get_script_folder
def get_odoo_addons_path( def get_odoo_addons_path(
ctx, root_path: Path, migration_step: dict, execution_context: str = False ctx, root_path: Path, migration_step: dict, execution_context: str = False
) -> str: ) -> str:
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step) repo_file = get_odoo_env_path(ctx, migration_step["version"]) / Path(
repo_file = get_odoo_env_path(ctx, odoo_version) / Path("repos.yml") "repos.yml"
)
base_module_folder = get_base_module_folder(migration_step) base_module_folder = get_base_module_folder(migration_step)
stream = open(repo_file, "r") stream = open(repo_file, "r")
data = yaml.safe_load(stream) data = yaml.safe_load(stream)
@ -49,37 +50,29 @@ def get_odoo_addons_path(
return addons_path return addons_path
def get_odoo_env_path(ctx, odoo_version: dict) -> Path: def get_odoo_env_path(ctx, odoo_version: float) -> Path:
folder_name = "env_%s" % str(odoo_version["release"]).rjust(4, "0") folder_name = "env_%s" % str(odoo_version).rjust(4, "0")
return ctx.obj["src_folder_path"] / folder_name return ctx.obj["src_folder_path"] / folder_name
def get_docker_image_tag(ctx, odoo_version: dict) -> str: def get_docker_image_tag(ctx, odoo_version: float) -> str:
"""Return a docker image tag, based on project name and odoo release""" """Return a docker image tag, based on project name and odoo version"""
return "odoo-openupgrade-wizard-image__%s__%s" % ( return "odoo-openupgrade-wizard-image__%s__%s" % (
ctx.obj["config"]["project_name"], 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: def get_docker_container_name(ctx, migration_step: dict) -> str:
"""Return a docker container name, based on project name, """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" % ( return "odoo-openupgrade-wizard-container__%s__%s__step-%s" % (
ctx.obj["config"]["project_name"], 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"), 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( def generate_odoo_command(
ctx, ctx,
migration_step: dict, 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 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. 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, migration_step["version"])
odoo_env_path = get_odoo_env_path(ctx, odoo_version)
custom_odoo_config_file = odoo_env_path / "odoo.cfg" custom_odoo_config_file = odoo_env_path / "odoo.cfg"
auto_generated_odoo_config_file = ( auto_generated_odoo_config_file = (
@ -187,10 +179,10 @@ def run_odoo(
# Ensure that Postgres container exist # Ensure that Postgres container exist
get_postgres_container(ctx) get_postgres_container(ctx)
logger.info( 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}" " in {execution_context} mode. Demo Data is {demo_text}"
" {stop_text} {init_text} {update_text}".format( " {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", db_text=database and "database '%s'" % database or "any databases",
execution_context=execution_context execution_context=execution_context
or migration_step["execution_context"], or migration_step["execution_context"],
@ -200,9 +192,8 @@ def run_odoo(
update_text=update and " (Update : %s)" % update or "", 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"] 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( log_file = "/env/log/{}____{}.log".format(
ctx.obj["log_prefix"], migration_step["complete_name"] ctx.obj["log_prefix"], migration_step["complete_name"]
) )
@ -227,7 +218,7 @@ def run_odoo(
) )
links.update({ctx.obj["config"]["postgres_container_name"]: "db"}) links.update({ctx.obj["config"]["postgres_container_name"]: "db"})
return run_container( 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), get_docker_container_name(ctx, migration_step),
command=command, command=command,
ports={ ports={
@ -267,10 +258,9 @@ def execute_click_odoo_python_files(
python_files = sorted(python_files) python_files = sorted(python_files)
# Prepare data information for docker # Prepare data information for docker
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
links = {ctx.obj["config"]["postgres_container_name"]: "db"} links = {ctx.obj["config"]["postgres_container_name"]: "db"}
env_path = ctx.obj["env_folder_path"] 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 # Generate odoo config file
log_file = "/env/log/{}____{}__post_migration.log".format( log_file = "/env/log/{}____{}__post_migration.log".format(
@ -296,7 +286,7 @@ def execute_click_odoo_python_files(
% (migration_step["complete_name"], python_file) % (migration_step["complete_name"], python_file)
) )
run_container( run_container(
get_docker_image_tag(ctx, odoo_version), get_docker_image_tag(ctx, migration_step["version"]),
get_docker_container_name(ctx, migration_step), get_docker_container_name(ctx, migration_step),
command=command, command=command,
ports={}, ports={},

View File

@ -21,29 +21,27 @@ from odoo_openupgrade_wizard.tools_odoo import (
class Analysis(object): class Analysis(object):
def __init__(self, ctx): def __init__(self, ctx):
self.modules = [] self.modules = []
self.initial_release = ctx.obj["config"]["odoo_versions"][0]["release"] self.initial_version = ctx.obj["config"]["odoo_versions"][0]
self.final_release = ctx.obj["config"]["odoo_versions"][-1]["release"] self.final_version = ctx.obj["config"]["odoo_versions"][-1]
self.all_releases = [ self.all_versions = [x for x in ctx.obj["config"]["odoo_versions"]]
x["release"] for x in ctx.obj["config"]["odoo_versions"]
]
def analyse_module_version(self, ctx, module_list): 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): for count in range(len(self.all_versions) - 1):
previous_release = self.all_releases[count] previous_version = self.all_versions[count]
current_release = self.all_releases[count + 1] current_version = self.all_versions[count + 1]
self._generate_module_version_next_release( self._generate_module_version_next_version(
ctx, previous_release, current_release ctx, previous_version, current_version
) )
def analyse_openupgrade_state(self, ctx): def analyse_openupgrade_state(self, ctx):
logger.info("Parsing openupgrade module coverage for each migration.") logger.info("Parsing openupgrade module coverage for each migration.")
coverage_analysis = {} coverage_analysis = {}
for release in self.all_releases[1:]: for version in self.all_versions[1:]:
coverage_analysis[release] = {} coverage_analysis[version] = {}
relative_path = get_coverage_relative_path({"release": release}) relative_path = get_coverage_relative_path(version)
env_folder_path = get_odoo_env_path(ctx, {"release": release}) env_folder_path = get_odoo_env_path(ctx, version)
coverage_path = env_folder_path / relative_path coverage_path = env_folder_path / relative_path
with open(coverage_path) as f: with open(coverage_path) as f:
lines = f.readlines() lines = f.readlines()
@ -55,11 +53,11 @@ class Analysis(object):
) )
splited_line = [x.strip() for x in clean_line.split("|") if x] splited_line = [x.strip() for x in clean_line.split("|") if x]
if len(splited_line) == 2: if len(splited_line) == 2:
coverage_analysis[release][splited_line[0]] = splited_line[ coverage_analysis[version][splited_line[0]] = splited_line[
1 1
] ]
if len(splited_line) == 3: if len(splited_line) == 3:
coverage_analysis[release][splited_line[0]] = ( coverage_analysis[version][splited_line[0]] = (
splited_line[1] + " " + splited_line[2] splited_line[1] + " " + splited_line[2]
).strip() ).strip()
elif len(splited_line) > 3: elif len(splited_line) > 3:
@ -74,16 +72,16 @@ class Analysis(object):
for module_version in list(odoo_module.module_versions.values()): for module_version in list(odoo_module.module_versions.values()):
module_version.analyse_openupgrade_state(coverage_analysis) module_version.analyse_openupgrade_state(coverage_analysis)
for release in self.all_releases[1:]: for version in self.all_versions[1:]:
odoo_env_path = get_odoo_env_path(ctx, {"release": release}) odoo_env_path = get_odoo_env_path(ctx, version)
openupgrade_analysis_files = get_openupgrade_analysis_files( openupgrade_analysis_files = get_openupgrade_analysis_files(
odoo_env_path, release odoo_env_path, version
) )
openupgrade_analysis_files = openupgrade_analysis_files openupgrade_analysis_files = openupgrade_analysis_files
for odoo_module in filter( for odoo_module in filter(
lambda x: x.module_type == "odoo", self.modules 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: if module_version:
module_version.analyse_openupgrade_work( module_version.analyse_openupgrade_work(
openupgrade_analysis_files openupgrade_analysis_files
@ -94,7 +92,7 @@ class Analysis(object):
lambda x: x.module_type != "odoo", self.modules lambda x: x.module_type != "odoo", self.modules
): ):
last_module_version = odoo_module.module_versions.get( last_module_version = odoo_module.module_versions.get(
self.final_release, False self.final_version, False
) )
if ( if (
@ -110,17 +108,17 @@ class Analysis(object):
for module_version in odoo_module.module_versions.values(): for module_version in odoo_module.module_versions.values():
module_version.estimate_workload(ctx) 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 = [] not_found_modules = []
logger.info( logger.info(
"Analyse version %s. (First Release)" % self.initial_release "Analyse version %s. (First version)" % self.initial_version
) )
# Instanciate a new odoo_module # Instanciate a new odoo_module
for module_name in module_list: for module_name in module_list:
addon_path = OdooModule.get_addon_path( addon_path = OdooModule.get_addon_path(
ctx, module_name, self.initial_release ctx, module_name, self.initial_version
) )
if addon_path: if addon_path:
repository_name = OdooModule.get_repository_name(addon_path) repository_name = OdooModule.get_repository_name(addon_path)
@ -129,54 +127,54 @@ class Analysis(object):
not in self.modules not in self.modules
): ):
logger.debug( logger.debug(
"Discovering module '%s' in %s for release %s" "Discovering module '%s' in %s for version %s"
% (module_name, repository_name, self.initial_release) % (module_name, repository_name, self.initial_version)
) )
new_odoo_module = OdooModule( new_odoo_module = OdooModule(
ctx, self, module_name, repository_name ctx, self, module_name, repository_name
) )
new_module_version = OdooModuleVersion( 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( new_odoo_module.module_versions.update(
{self.initial_release: new_module_version} {self.initial_version: new_module_version}
) )
self.modules.append(new_odoo_module) self.modules.append(new_odoo_module)
else: else:
logger.error( logger.error(
"Module %s not found for release %s." "Module %s not found for version %s."
% (module_name, self.initial_release) % (module_name, self.initial_version)
) )
not_found_modules.append(module_name) not_found_modules.append(module_name)
if not_found_modules: if not_found_modules:
raise ValueError( 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" " 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." " 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( def _generate_module_version_next_version(
self, ctx, previous_release, current_release self, ctx, previous_version, current_version
): ):
logger.info( logger.info(
"Analyse change between %s and %s" "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_module_name,
apriori_relative_path, 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( apriori_module_path = OdooModule.get_addon_path(
ctx, apriori_module_name, current_release ctx, apriori_module_name, current_version
) )
if not apriori_module_path: if not apriori_module_path:
raise ValueError( raise ValueError(
"Unable to find the path of the module %s for the release %s" "Unable to find the path of the module %s for the version %s"
% (apriori_module_name, current_release) % (apriori_module_name, current_version)
) )
apriori_absolute_path = ( apriori_absolute_path = (
apriori_module_path apriori_module_path
@ -202,8 +200,8 @@ class Analysis(object):
logger.debug( logger.debug(
"%s -> %s : %s renamed into %s" "%s -> %s : %s renamed into %s"
% ( % (
previous_release, previous_version,
current_release, current_version,
odoo_module.name, odoo_module.name,
new_module_name, new_module_name,
) )
@ -214,8 +212,8 @@ class Analysis(object):
logger.debug( logger.debug(
"%s -> %s : %s merged into %s" "%s -> %s : %s merged into %s"
% ( % (
previous_release, previous_version,
current_release, current_version,
odoo_module.name, odoo_module.name,
new_module_name, new_module_name,
) )
@ -225,13 +223,13 @@ class Analysis(object):
if state and new_module_name != odoo_module.name: if state and new_module_name != odoo_module.name:
# Ensure that the module exists in self.modules # Ensure that the module exists in self.modules
new_addon_path = OdooModule.get_addon_path( new_addon_path = OdooModule.get_addon_path(
ctx, new_module_name, current_release ctx, new_module_name, current_version
) )
if not new_addon_path: if not new_addon_path:
raise ValueError( 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." " Analyse can not be done."
% (new_module_name, current_release) % (new_module_name, current_version)
) )
else: else:
new_repository_name = OdooModule.get_repository_name( new_repository_name = OdooModule.get_repository_name(
@ -242,11 +240,11 @@ class Analysis(object):
not in self.modules not in self.modules
): ):
logger.debug( logger.debug(
"Discovering module '%s' in %s for release %s" "Discovering module '%s' in %s for version %s"
% ( % (
new_module_name, new_module_name,
new_repository_name, new_repository_name,
current_release, current_version,
) )
) )
new_odoo_module = OdooModule( new_odoo_module = OdooModule(
@ -255,19 +253,19 @@ class Analysis(object):
self.modules.append(new_odoo_module) self.modules.append(new_odoo_module)
new_odoo_module.module_versions.update( new_odoo_module.module_versions.update(
{ {
current_release: OdooModuleVersion( current_version: OdooModuleVersion(
current_release, current_version,
new_odoo_module, new_odoo_module,
new_addon_path, 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_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 # the loss is normal
if previous_module_version and previous_module_version.state in [ if previous_module_version and previous_module_version.state in [
"merged", "merged",
@ -277,12 +275,12 @@ class Analysis(object):
state = "normal_loss" state = "normal_loss"
new_addon_path = OdooModule.get_addon_path( new_addon_path = OdooModule.get_addon_path(
ctx, odoo_module.name, current_release ctx, odoo_module.name, current_version
) )
odoo_module.module_versions.update( odoo_module.module_versions.update(
{ {
current_release: OdooModuleVersion( current_version: OdooModuleVersion(
current_release, current_version,
odoo_module, odoo_module,
new_addon_path, new_addon_path,
state=state, state=state,
@ -336,23 +334,23 @@ class OdooModule(object):
else: else:
self.module_type = "custom" self.module_type = "custom"
def get_module_version(self, current_release): def get_module_version(self, current_version):
res = self.module_versions.get(current_release, False) res = self.module_versions.get(current_version, False)
return res return res
@classmethod @classmethod
def get_addon_path(cls, ctx, module_name, current_release): def get_addon_path(cls, ctx, module_name, current_version):
"""Search the module in all the addons path of the current release """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. and return the addon path of the module, or False if not found.
For exemple find_repository(ctx, 'web_responsive', 12.0) For exemple find_repository(ctx, 'web_responsive', 12.0)
'/PATH_TO_LOCAL_ENV/src/OCA/web' '/PATH_TO_LOCAL_ENV/src/OCA/web'
""" """
# Try to find the repository that contains the module # 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( addons_path = get_odoo_addons_path(
ctx, ctx,
main_path, main_path,
{"release": current_release, "execution_context": "openupgrade"}, {"version": current_version, "execution_context": "openupgrade"},
) )
for addon_path in addons_path: for addon_path in addons_path:
if (addon_path / module_name).exists(): if (addon_path / module_name).exists():
@ -427,13 +425,13 @@ class OdooModuleVersion(object):
def __init__( def __init__(
self, self,
release, version,
odoo_module, odoo_module,
addon_path, addon_path,
state=False, state=False,
target_module=False, target_module=False,
): ):
self.release = release self.version = version
self.odoo_module = odoo_module self.odoo_module = odoo_module
self.addon_path = addon_path self.addon_path = addon_path
self.state = state self.state = state
@ -471,8 +469,8 @@ class OdooModuleVersion(object):
return return
if self.odoo_module.module_type == "odoo": if self.odoo_module.module_type == "odoo":
if self.release == self.odoo_module.analyse.initial_release: if self.version == self.odoo_module.analyse.initial_version:
# No work to do for the initial release # No work to do for the initial version
return return
if self.openupgrade_state and ( if self.openupgrade_state and (
self.openupgrade_state.lower().startswith("done") self.openupgrade_state.lower().startswith("done")
@ -498,8 +496,8 @@ class OdooModuleVersion(object):
) )
# OCA / Custom Module # OCA / Custom Module
if self.release != self.odoo_module.analyse.final_release: if self.version != self.odoo_module.analyse.final_version:
# No need to work for intermediate release (in theory ;-)) # No need to work for intermediate version (in theory ;-))
return return
if self.addon_path: if self.addon_path:
@ -510,8 +508,8 @@ class OdooModuleVersion(object):
self.workload = ( self.workload = (
# Minimal port time # Minimal port time
port_minimal_time port_minimal_time
# Add time per release # Add time per version
+ (self.release - previous_module_version.release) + (self.version - previous_module_version.version)
* port_per_version * port_per_version
# Add python time # Add python time
+ (port_per_python_line_time * previous_module_version.python_code) + (port_per_python_line_time * previous_module_version.python_code)
@ -558,14 +556,14 @@ class OdooModuleVersion(object):
self.javascript_code += file_res.code self.javascript_code += file_res.code
def analyse_openupgrade_state(self, coverage_analysis): 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 return
self.openupgrade_state = coverage_analysis[self.release].get( self.openupgrade_state = coverage_analysis[self.version].get(
self.odoo_module.name, False self.odoo_module.name, False
) )
def analyse_openupgrade_work(self, analysis_files): 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 return
analysis_file = analysis_files.get(self.odoo_module.name, False) analysis_file = analysis_files.get(self.odoo_module.name, False)
@ -641,7 +639,7 @@ class OdooModuleVersion(object):
if self.addon_path: if self.addon_path:
if ( if (
self.odoo_module.module_type == "odoo" 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 ( if self.openupgrade_state and (
self.openupgrade_state.lower().startswith("done") self.openupgrade_state.lower().startswith("done")
@ -654,7 +652,7 @@ class OdooModuleVersion(object):
return "orange" return "orange"
return "lightgreen" return "lightgreen"
else: 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"]: if self.state in ["merged", "renamed", "normal_loss"]:
# Normal case, the previous version has been renamed # Normal case, the previous version has been renamed
# or merged # or merged
@ -664,7 +662,7 @@ class OdooModuleVersion(object):
# A core module disappeared and has not been merged # A core module disappeared and has not been merged
# or renamed # or renamed
return "red" return "red"
elif self.release != self.odoo_module.analyse.final_release: elif self.version != self.odoo_module.analyse.final_version:
return "lightgray" return "lightgray"
else: else:
return "orange" return "orange"
@ -673,7 +671,7 @@ class OdooModuleVersion(object):
if self.addon_path: if self.addon_path:
if ( if (
self.odoo_module.module_type == "odoo" 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( if self.openupgrade_state.lower().startswith(
"done" "done"
@ -696,10 +694,10 @@ class OdooModuleVersion(object):
# A core module disappeared and has not been merged # A core module disappeared and has not been merged
# or renamed # or renamed
return "Module lost" return "Module lost"
elif self.release != self.odoo_module.analyse.final_release: elif self.version != self.odoo_module.analyse.final_version:
return "Unported" return "Unported"
else: else:
return ( return (
"To port from %s" "To port from %s"
% self.get_last_existing_version().release % self.get_last_existing_version().version
) )

View File

@ -13,8 +13,8 @@ def test_cli_init():
"--log-level=DEBUG", "--log-level=DEBUG",
"init", "init",
"--project-name=test-cli", "--project-name=test-cli",
"--initial-release=13.0", "--initial-version=13.0",
"--final-release=14.0", "--final-version=14.0",
"--extra-repository=" "--extra-repository="
"OCA/web,OCA/server-tools,OCA/bank-statement-import", "OCA/web,OCA/server-tools,OCA/bank-statement-import",
] ]

View File

@ -9,7 +9,7 @@ def test_cli_docker_build():
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"docker-build", "docker-build",
"--releases=13.0,14.0", "--versions=13.0,14.0",
] ]
) )

View File

@ -15,7 +15,7 @@ def test_cli_generate_module_analysis():
ctx = build_ctx_from_config_file() ctx = build_ctx_from_config_file()
# identify main analysis file of openupgrade # 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" "src/openupgrade/openupgrade_scripts/scripts"
"/base/14.0.1.3/upgrade_general_log.txt" "/base/14.0.1.3/upgrade_general_log.txt"
) )

View File

@ -1,4 +1,3 @@
project_name: test-cli project_name: test-cli
postgres_image_name: postgres:13 postgres_image_name: postgres:13
@ -9,26 +8,22 @@ odoo_default_country_code: FR
odoo_versions: odoo_versions:
- 13.0
- release: 13.0 - 14.0
- release: 14.0
migration_steps: migration_steps:
- name: 1 - name: 1
release: 13.0 version: 13.0
execution_context: regular execution_context: regular
complete_name: step_01__update__13.0 complete_name: step_01__update__13.0
- name: 2 - name: 2
release: 14.0 version: 14.0
execution_context: openupgrade execution_context: openupgrade
complete_name: step_02__upgrade__14.0 complete_name: step_02__upgrade__14.0
- name: 3 - name: 3
release: 14.0 version: 14.0
execution_context: regular execution_context: regular
complete_name: step_03__update__14.0 complete_name: step_03__update__14.0