Merge branch 'dev-5-execution-context-and-jobs' into 'main'
[IMP] allow to call run with a specific execution_context See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!6
This commit is contained in:
commit
aa7fec5fd1
|
|
@ -57,9 +57,6 @@ def generate_module_analysis(ctx, step, database, modules):
|
|||
|
||||
modules = modules and modules.split(",") or []
|
||||
|
||||
# Force to be in openupgrade mode
|
||||
initial_step["action"] = final_step["action"] = "upgrade"
|
||||
|
||||
try:
|
||||
# INITIAL : Run odoo and install analysis module
|
||||
run_odoo(
|
||||
|
|
@ -68,6 +65,7 @@ def generate_module_analysis(ctx, step, database, modules):
|
|||
database=initial_database,
|
||||
detached_container=False,
|
||||
stop_after_init=True,
|
||||
execution_context="openupgrade",
|
||||
init=get_upgrade_analysis_module(initial_step),
|
||||
)
|
||||
|
||||
|
|
@ -76,6 +74,7 @@ def generate_module_analysis(ctx, step, database, modules):
|
|||
ctx,
|
||||
initial_step,
|
||||
database=initial_database,
|
||||
execution_context="openupgrade",
|
||||
detached_container=True,
|
||||
)
|
||||
# INITIAL : install modules to analyse and generate records
|
||||
|
|
@ -96,6 +95,7 @@ def generate_module_analysis(ctx, step, database, modules):
|
|||
detached_container=False,
|
||||
stop_after_init=True,
|
||||
init=get_upgrade_analysis_module(final_step),
|
||||
execution_context="openupgrade",
|
||||
alternative_xml_rpc_port=alternative_xml_rpc_port,
|
||||
)
|
||||
|
||||
|
|
@ -109,6 +109,7 @@ def generate_module_analysis(ctx, step, database, modules):
|
|||
database=final_database,
|
||||
detached_container=True,
|
||||
alternative_xml_rpc_port=alternative_xml_rpc_port,
|
||||
execution_context="openupgrade",
|
||||
links={initial_container.name: odoo_initial_host_name},
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,19 @@ from odoo_openupgrade_wizard.tools_system import git_aggregate
|
|||
|
||||
@click.command()
|
||||
@releases_options
|
||||
@click.option(
|
||||
"-j",
|
||||
"--jobs",
|
||||
type=int,
|
||||
default=10,
|
||||
help="Jobs used to call the git-aggregate command."
|
||||
" reasonably set to 10 by default.",
|
||||
)
|
||||
@click.pass_context
|
||||
def get_code(ctx, releases):
|
||||
def get_code(ctx, releases, jobs):
|
||||
"""Get code by running gitaggregate command for each release"""
|
||||
|
||||
for odoo_version in get_odoo_versions_from_options(ctx, releases):
|
||||
folder_path = get_odoo_env_path(ctx, odoo_version)
|
||||
repo_file_path = folder_path / "repos.yml"
|
||||
git_aggregate(folder_path, repo_file_path)
|
||||
git_aggregate(folder_path, repo_file_path, jobs)
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ def init(
|
|||
steps = [
|
||||
{
|
||||
"name": 1,
|
||||
"action": "update",
|
||||
"execution_context": "regular",
|
||||
"release": odoo_versions[0]["release"],
|
||||
"complete_name": "step_01__update__%s"
|
||||
% (odoo_versions[0]["release"]),
|
||||
|
|
@ -87,7 +87,7 @@ def init(
|
|||
steps.append(
|
||||
{
|
||||
"name": step_nbr,
|
||||
"action": "upgrade",
|
||||
"execution_context": "openupgrade",
|
||||
"release": odoo_version["release"],
|
||||
"complete_name": "step_%s__upgrade__%s"
|
||||
% (str(step_nbr).rjust(2, "0"), odoo_version["release"]),
|
||||
|
|
@ -100,7 +100,7 @@ def init(
|
|||
steps.append(
|
||||
{
|
||||
"name": step_nbr,
|
||||
"action": "update",
|
||||
"execution_context": "regular",
|
||||
"release": odoo_versions[-1]["release"],
|
||||
"complete_name": "step_%s__update__%s"
|
||||
% (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,
|
||||
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
|
||||
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)
|
||||
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,
|
||||
init=init_modules,
|
||||
stop_after_init=stop_after_init,
|
||||
execution_context=execution_context,
|
||||
)
|
||||
if not stop_after_init:
|
||||
logger.info(
|
||||
|
|
|
|||
|
|
@ -89,11 +89,18 @@ def get_odoo_run_command(migration_step: dict) -> str:
|
|||
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.
|
||||
(./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"
|
||||
|
||||
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."""
|
||||
if (
|
||||
migration_step["release"] >= 14.0
|
||||
and migration_step["action"] == "upgrade"
|
||||
and migration_step["execution_context"] == "openupgrade"
|
||||
):
|
||||
return ["openupgrade_framework"]
|
||||
return []
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ migration_steps:
|
|||
{% for step in steps %}
|
||||
- name: {{ step['name'] }}
|
||||
release: {{ step['release'] }}
|
||||
action: {{ step['action'] }}
|
||||
execution_context: {{ step['execution_context'] }}
|
||||
complete_name: {{ step['complete_name'] }}
|
||||
{% 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
|
||||
|
||||
|
||||
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)
|
||||
repo_file = get_odoo_env_path(ctx, odoo_version) / Path("repos.yml")
|
||||
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 = []
|
||||
for key in data.keys():
|
||||
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
|
||||
addons_path.append(path / Path("addons"))
|
||||
addons_path.append(
|
||||
|
|
@ -79,6 +83,7 @@ def get_odoo_version_from_migration_step(ctx, migration_step: dict) -> dict:
|
|||
def generate_odoo_command(
|
||||
ctx,
|
||||
migration_step: dict,
|
||||
execution_context: str,
|
||||
database: str,
|
||||
update: str,
|
||||
init: str,
|
||||
|
|
@ -94,7 +99,7 @@ def generate_odoo_command(
|
|||
demo_cmd = not demo and "--without-demo all" or ""
|
||||
command = (
|
||||
Path("/odoo_env")
|
||||
/ Path(get_odoo_folder(migration_step))
|
||||
/ Path(get_odoo_folder(migration_step, execution_context))
|
||||
/ Path(get_odoo_run_command(migration_step))
|
||||
)
|
||||
result = (
|
||||
|
|
@ -110,7 +115,9 @@ def generate_odoo_command(
|
|||
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
|
||||
in the according environment (defined by migration_step)
|
||||
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)
|
||||
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,
|
||||
shell: bool = False,
|
||||
demo: bool = False,
|
||||
execution_context: str = False,
|
||||
alternative_xml_rpc_port: int = False,
|
||||
links: dict = {},
|
||||
):
|
||||
|
|
@ -180,13 +188,12 @@ def run_odoo(
|
|||
get_postgres_container(ctx)
|
||||
logger.info(
|
||||
"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(
|
||||
release=migration_step["release"],
|
||||
db_text=database and "database '%s'" % database or "any databases",
|
||||
action=migration_step["action"] == "update"
|
||||
and "regular"
|
||||
or "OpenUpgrade",
|
||||
execution_context=execution_context
|
||||
or migration_step["execution_context"],
|
||||
demo_text=demo and "enabled" or "disabled",
|
||||
stop_text=stop_after_init and " (stop-after-init)" or "",
|
||||
init_text=init and " (Init : %s)" % init or "",
|
||||
|
|
@ -199,11 +206,12 @@ def run_odoo(
|
|||
log_file = "/env/log/{}____{}.log".format(
|
||||
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(
|
||||
ctx,
|
||||
migration_step,
|
||||
execution_context,
|
||||
database=database,
|
||||
update=update,
|
||||
init=init,
|
||||
|
|
@ -240,7 +248,11 @@ def kill_odoo(ctx, migration_step: dict):
|
|||
|
||||
|
||||
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:
|
||||
|
|
@ -264,7 +276,7 @@ def execute_click_odoo_python_files(
|
|||
log_file = "/env/log/{}____{}__post_migration.log".format(
|
||||
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:
|
||||
# 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(
|
||||
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_module_path
|
||||
/ Path(apriori_module_name)
|
||||
|
|
@ -345,11 +350,14 @@ class OdooModule(object):
|
|||
# Try to find the repository that contains the module
|
||||
main_path = get_odoo_env_path(ctx, {"release": current_release})
|
||||
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:
|
||||
if (addon_path / module_name).exists():
|
||||
return addon_path
|
||||
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -70,12 +70,12 @@ def ensure_file_exists_from_template(
|
|||
f.close()
|
||||
|
||||
|
||||
def git_aggregate(folder_path: Path, config_path: Path):
|
||||
def git_aggregate(folder_path: Path, config_path: Path, jobs: int):
|
||||
|
||||
args = argparse.Namespace(
|
||||
command="aggregate",
|
||||
config=str(config_path),
|
||||
jobs=1,
|
||||
jobs=jobs,
|
||||
dirmatch=None,
|
||||
do_push=False,
|
||||
expand_env=False,
|
||||
|
|
|
|||
|
|
@ -19,17 +19,17 @@ migration_steps:
|
|||
|
||||
- name: 1
|
||||
release: 13.0
|
||||
action: update
|
||||
execution_context: regular
|
||||
complete_name: step_01__update__13.0
|
||||
|
||||
- name: 2
|
||||
release: 14.0
|
||||
action: upgrade
|
||||
execution_context: openupgrade
|
||||
complete_name: step_02__upgrade__14.0
|
||||
|
||||
- name: 3
|
||||
release: 14.0
|
||||
action: update
|
||||
execution_context: regular
|
||||
complete_name: step_03__update__14.0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user