[IMP] allow to call run with a specific execution_context
This commit is contained in:
parent
6ca28fd3a9
commit
d23804f4b4
|
|
@ -57,9 +57,6 @@ def generate_module_analysis(ctx, step, database, modules):
|
||||||
|
|
||||||
modules = modules and modules.split(",") or []
|
modules = modules and modules.split(",") or []
|
||||||
|
|
||||||
# Force to be in openupgrade mode
|
|
||||||
initial_step["action"] = final_step["action"] = "upgrade"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# INITIAL : Run odoo and install analysis module
|
# INITIAL : Run odoo and install analysis module
|
||||||
run_odoo(
|
run_odoo(
|
||||||
|
|
@ -68,6 +65,7 @@ def generate_module_analysis(ctx, step, database, modules):
|
||||||
database=initial_database,
|
database=initial_database,
|
||||||
detached_container=False,
|
detached_container=False,
|
||||||
stop_after_init=True,
|
stop_after_init=True,
|
||||||
|
execution_context="openupgrade",
|
||||||
init=get_upgrade_analysis_module(initial_step),
|
init=get_upgrade_analysis_module(initial_step),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -76,6 +74,7 @@ def generate_module_analysis(ctx, step, database, modules):
|
||||||
ctx,
|
ctx,
|
||||||
initial_step,
|
initial_step,
|
||||||
database=initial_database,
|
database=initial_database,
|
||||||
|
execution_context="openupgrade",
|
||||||
detached_container=True,
|
detached_container=True,
|
||||||
)
|
)
|
||||||
# INITIAL : install modules to analyse and generate records
|
# INITIAL : install modules to analyse and generate records
|
||||||
|
|
@ -96,6 +95,7 @@ def generate_module_analysis(ctx, step, database, modules):
|
||||||
detached_container=False,
|
detached_container=False,
|
||||||
stop_after_init=True,
|
stop_after_init=True,
|
||||||
init=get_upgrade_analysis_module(final_step),
|
init=get_upgrade_analysis_module(final_step),
|
||||||
|
execution_context="openupgrade",
|
||||||
alternative_xml_rpc_port=alternative_xml_rpc_port,
|
alternative_xml_rpc_port=alternative_xml_rpc_port,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -109,6 +109,7 @@ def generate_module_analysis(ctx, step, database, modules):
|
||||||
database=final_database,
|
database=final_database,
|
||||||
detached_container=True,
|
detached_container=True,
|
||||||
alternative_xml_rpc_port=alternative_xml_rpc_port,
|
alternative_xml_rpc_port=alternative_xml_rpc_port,
|
||||||
|
execution_context="openupgrade",
|
||||||
links={initial_container.name: odoo_initial_host_name},
|
links={initial_container.name: odoo_initial_host_name},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ def init(
|
||||||
steps = [
|
steps = [
|
||||||
{
|
{
|
||||||
"name": 1,
|
"name": 1,
|
||||||
"action": "update",
|
"execution_context": "regular",
|
||||||
"release": odoo_versions[0]["release"],
|
"release": odoo_versions[0]["release"],
|
||||||
"complete_name": "step_01__update__%s"
|
"complete_name": "step_01__update__%s"
|
||||||
% (odoo_versions[0]["release"]),
|
% (odoo_versions[0]["release"]),
|
||||||
|
|
@ -87,7 +87,7 @@ def init(
|
||||||
steps.append(
|
steps.append(
|
||||||
{
|
{
|
||||||
"name": step_nbr,
|
"name": step_nbr,
|
||||||
"action": "upgrade",
|
"execution_context": "openupgrade",
|
||||||
"release": odoo_version["release"],
|
"release": odoo_version["release"],
|
||||||
"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["release"]),
|
||||||
|
|
@ -100,7 +100,7 @@ def init(
|
||||||
steps.append(
|
steps.append(
|
||||||
{
|
{
|
||||||
"name": step_nbr,
|
"name": step_nbr,
|
||||||
"action": "update",
|
"execution_context": "regular",
|
||||||
"release": odoo_versions[-1]["release"],
|
"release": odoo_versions[-1]["release"],
|
||||||
"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]["release"]),
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,16 @@ from odoo_openupgrade_wizard.tools_postgres import ensure_database
|
||||||
type=str,
|
type=str,
|
||||||
help="List of modules to install. Equivalent to -i odoo options.",
|
help="List of modules to install. Equivalent to -i odoo options.",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"-e",
|
||||||
|
"--execution-context",
|
||||||
|
type=click.Choice(["regular", "openupgrade"]),
|
||||||
|
help="Force to use an openupgrade (OCA/openupgrade)"
|
||||||
|
" or a regular (odoo/odoo or OCA/OCB) base code when running odoo."
|
||||||
|
" Let empty to use the defaut execution of the migration step.",
|
||||||
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def run(ctx, step, database, stop_after_init, init_modules):
|
def run(ctx, step, database, stop_after_init, init_modules, execution_context):
|
||||||
|
|
||||||
migration_step = get_migration_step_from_options(ctx, step)
|
migration_step = get_migration_step_from_options(ctx, step)
|
||||||
ensure_database(ctx, database, state="present")
|
ensure_database(ctx, database, state="present")
|
||||||
|
|
@ -40,6 +48,7 @@ def run(ctx, step, database, stop_after_init, init_modules):
|
||||||
detached_container=not stop_after_init,
|
detached_container=not stop_after_init,
|
||||||
init=init_modules,
|
init=init_modules,
|
||||||
stop_after_init=stop_after_init,
|
stop_after_init=stop_after_init,
|
||||||
|
execution_context=execution_context,
|
||||||
)
|
)
|
||||||
if not stop_after_init:
|
if not stop_after_init:
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,18 @@ def get_odoo_run_command(migration_step: dict) -> str:
|
||||||
return "odoo.py"
|
return "odoo.py"
|
||||||
|
|
||||||
|
|
||||||
def get_odoo_folder(migration_step: dict) -> str:
|
def get_odoo_folder(
|
||||||
|
migration_step: dict, execution_context: str = False
|
||||||
|
) -> str:
|
||||||
"""return the main odoo folder, depending on the migration step.
|
"""return the main odoo folder, depending on the migration step.
|
||||||
(./src/odoo, ./src/openupgrade, ...)"""
|
(./src/odoo, ./src/openupgrade, ...)"""
|
||||||
|
|
||||||
if migration_step["action"] == "update":
|
if execution_context == "regular":
|
||||||
|
return "src/odoo"
|
||||||
|
elif execution_context == "openupgrade" and migration_step["release"] < 14:
|
||||||
|
return "src/openupgrade"
|
||||||
|
|
||||||
|
if migration_step["execution_context"] == "regular":
|
||||||
return "src/odoo"
|
return "src/odoo"
|
||||||
|
|
||||||
if migration_step["release"] >= 14.0:
|
if migration_step["release"] >= 14.0:
|
||||||
|
|
@ -126,7 +133,7 @@ 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["release"] >= 14.0
|
||||||
and migration_step["action"] == "upgrade"
|
and migration_step["execution_context"] == "openupgrade"
|
||||||
):
|
):
|
||||||
return ["openupgrade_framework"]
|
return ["openupgrade_framework"]
|
||||||
return []
|
return []
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ migration_steps:
|
||||||
{% for step in steps %}
|
{% for step in steps %}
|
||||||
- name: {{ step['name'] }}
|
- name: {{ step['name'] }}
|
||||||
release: {{ step['release'] }}
|
release: {{ step['release'] }}
|
||||||
action: {{ step['action'] }}
|
execution_context: {{ step['execution_context'] }}
|
||||||
complete_name: {{ step['complete_name'] }}
|
complete_name: {{ step['complete_name'] }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,9 @@ from odoo_openupgrade_wizard.tools_postgres import get_postgres_container
|
||||||
from odoo_openupgrade_wizard.tools_system import get_script_folder
|
from odoo_openupgrade_wizard.tools_system import get_script_folder
|
||||||
|
|
||||||
|
|
||||||
def get_odoo_addons_path(ctx, root_path: Path, migration_step: dict) -> str:
|
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)
|
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, odoo_version) / Path("repos.yml")
|
||||||
base_module_folder = get_base_module_folder(migration_step)
|
base_module_folder = get_base_module_folder(migration_step)
|
||||||
|
|
@ -31,7 +33,9 @@ def get_odoo_addons_path(ctx, root_path: Path, migration_step: dict) -> str:
|
||||||
addons_path = []
|
addons_path = []
|
||||||
for key in data.keys():
|
for key in data.keys():
|
||||||
path = root_path / Path(key)
|
path = root_path / Path(key)
|
||||||
if str(path).endswith(get_odoo_folder(migration_step)):
|
if str(path).endswith(
|
||||||
|
get_odoo_folder(migration_step, execution_context)
|
||||||
|
):
|
||||||
# Add two folder for odoo folder
|
# Add two folder for odoo folder
|
||||||
addons_path.append(path / Path("addons"))
|
addons_path.append(path / Path("addons"))
|
||||||
addons_path.append(
|
addons_path.append(
|
||||||
|
|
@ -79,6 +83,7 @@ def get_odoo_version_from_migration_step(ctx, migration_step: dict) -> dict:
|
||||||
def generate_odoo_command(
|
def generate_odoo_command(
|
||||||
ctx,
|
ctx,
|
||||||
migration_step: dict,
|
migration_step: dict,
|
||||||
|
execution_context: str,
|
||||||
database: str,
|
database: str,
|
||||||
update: str,
|
update: str,
|
||||||
init: str,
|
init: str,
|
||||||
|
|
@ -94,7 +99,7 @@ def generate_odoo_command(
|
||||||
demo_cmd = not demo and "--without-demo all" or ""
|
demo_cmd = not demo and "--without-demo all" or ""
|
||||||
command = (
|
command = (
|
||||||
Path("/odoo_env")
|
Path("/odoo_env")
|
||||||
/ Path(get_odoo_folder(migration_step))
|
/ Path(get_odoo_folder(migration_step, execution_context))
|
||||||
/ Path(get_odoo_run_command(migration_step))
|
/ Path(get_odoo_run_command(migration_step))
|
||||||
)
|
)
|
||||||
result = (
|
result = (
|
||||||
|
|
@ -110,7 +115,9 @@ def generate_odoo_command(
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def generate_odoo_config_file(ctx, migration_step, log_file):
|
def generate_odoo_config_file(
|
||||||
|
ctx, migration_step, log_file, execution_context
|
||||||
|
):
|
||||||
"""Create a config file name _auto_generated_odoo.cfg
|
"""Create a config file name _auto_generated_odoo.cfg
|
||||||
in the according environment (defined by migration_step)
|
in the according environment (defined by migration_step)
|
||||||
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
|
||||||
|
|
@ -133,7 +140,7 @@ def generate_odoo_config_file(ctx, migration_step, log_file):
|
||||||
[
|
[
|
||||||
str(x)
|
str(x)
|
||||||
for x in get_odoo_addons_path(
|
for x in get_odoo_addons_path(
|
||||||
ctx, Path("/odoo_env"), migration_step
|
ctx, Path("/odoo_env"), migration_step, execution_context
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
@ -173,6 +180,7 @@ def run_odoo(
|
||||||
stop_after_init: bool = False,
|
stop_after_init: bool = False,
|
||||||
shell: bool = False,
|
shell: bool = False,
|
||||||
demo: bool = False,
|
demo: bool = False,
|
||||||
|
execution_context: str = False,
|
||||||
alternative_xml_rpc_port: int = False,
|
alternative_xml_rpc_port: int = False,
|
||||||
links: dict = {},
|
links: dict = {},
|
||||||
):
|
):
|
||||||
|
|
@ -180,13 +188,12 @@ def run_odoo(
|
||||||
get_postgres_container(ctx)
|
get_postgres_container(ctx)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Launching Odoo Container (Release {release}) for {db_text}"
|
"Launching Odoo Container (Release {release}) for {db_text}"
|
||||||
" in {action} 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"],
|
release=migration_step["release"],
|
||||||
db_text=database and "database '%s'" % database or "any databases",
|
db_text=database and "database '%s'" % database or "any databases",
|
||||||
action=migration_step["action"] == "update"
|
execution_context=execution_context
|
||||||
and "regular"
|
or migration_step["execution_context"],
|
||||||
or "OpenUpgrade",
|
|
||||||
demo_text=demo and "enabled" or "disabled",
|
demo_text=demo and "enabled" or "disabled",
|
||||||
stop_text=stop_after_init and " (stop-after-init)" or "",
|
stop_text=stop_after_init and " (stop-after-init)" or "",
|
||||||
init_text=init and " (Init : %s)" % init or "",
|
init_text=init and " (Init : %s)" % init or "",
|
||||||
|
|
@ -199,11 +206,12 @@ def run_odoo(
|
||||||
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"]
|
||||||
)
|
)
|
||||||
generate_odoo_config_file(ctx, migration_step, log_file)
|
generate_odoo_config_file(ctx, migration_step, log_file, execution_context)
|
||||||
|
|
||||||
command = generate_odoo_command(
|
command = generate_odoo_command(
|
||||||
ctx,
|
ctx,
|
||||||
migration_step,
|
migration_step,
|
||||||
|
execution_context,
|
||||||
database=database,
|
database=database,
|
||||||
update=update,
|
update=update,
|
||||||
init=init,
|
init=init,
|
||||||
|
|
@ -240,7 +248,11 @@ def kill_odoo(ctx, migration_step: dict):
|
||||||
|
|
||||||
|
|
||||||
def execute_click_odoo_python_files(
|
def execute_click_odoo_python_files(
|
||||||
ctx, database: str, migration_step: dict, python_files: list = []
|
ctx,
|
||||||
|
database: str,
|
||||||
|
migration_step: dict,
|
||||||
|
python_files: list = [],
|
||||||
|
execution_context: str = False,
|
||||||
):
|
):
|
||||||
|
|
||||||
if not python_files:
|
if not python_files:
|
||||||
|
|
@ -264,7 +276,7 @@ def execute_click_odoo_python_files(
|
||||||
log_file = "/env/log/{}____{}__post_migration.log".format(
|
log_file = "/env/log/{}____{}__post_migration.log".format(
|
||||||
ctx.obj["log_prefix"], migration_step["complete_name"]
|
ctx.obj["log_prefix"], migration_step["complete_name"]
|
||||||
)
|
)
|
||||||
generate_odoo_config_file(ctx, migration_step, log_file)
|
generate_odoo_config_file(ctx, migration_step, log_file, execution_context)
|
||||||
|
|
||||||
for python_file in python_files:
|
for python_file in python_files:
|
||||||
# TODO, check if we should set python2 for old version of Odoo
|
# TODO, check if we should set python2 for old version of Odoo
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,11 @@ class Analysis(object):
|
||||||
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_release
|
||||||
)
|
)
|
||||||
|
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)
|
||||||
|
)
|
||||||
apriori_absolute_path = (
|
apriori_absolute_path = (
|
||||||
apriori_module_path
|
apriori_module_path
|
||||||
/ Path(apriori_module_name)
|
/ Path(apriori_module_name)
|
||||||
|
|
@ -345,11 +350,14 @@ class OdooModule(object):
|
||||||
# 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, {"release": current_release})
|
||||||
addons_path = get_odoo_addons_path(
|
addons_path = get_odoo_addons_path(
|
||||||
ctx, main_path, {"release": current_release, "action": "upgrade"}
|
ctx,
|
||||||
|
main_path,
|
||||||
|
{"release": current_release, "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():
|
||||||
return addon_path
|
return addon_path
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,17 @@ migration_steps:
|
||||||
|
|
||||||
- name: 1
|
- name: 1
|
||||||
release: 13.0
|
release: 13.0
|
||||||
action: update
|
execution_context: regular
|
||||||
complete_name: step_01__update__13.0
|
complete_name: step_01__update__13.0
|
||||||
|
|
||||||
- name: 2
|
- name: 2
|
||||||
release: 14.0
|
release: 14.0
|
||||||
action: upgrade
|
execution_context: openupgrade
|
||||||
complete_name: step_02__upgrade__14.0
|
complete_name: step_02__upgrade__14.0
|
||||||
|
|
||||||
- name: 3
|
- name: 3
|
||||||
release: 14.0
|
release: 14.0
|
||||||
action: update
|
execution_context: regular
|
||||||
complete_name: step_03__update__14.0
|
complete_name: step_03__update__14.0
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user