wip
This commit is contained in:
parent
4656329ef0
commit
e5813612ca
|
|
@ -14,6 +14,9 @@ from odoo_openupgrade_wizard.cli_execute_script_python import (
|
||||||
execute_script_python,
|
execute_script_python,
|
||||||
)
|
)
|
||||||
from odoo_openupgrade_wizard.cli_execute_script_sql import execute_script_sql
|
from odoo_openupgrade_wizard.cli_execute_script_sql import execute_script_sql
|
||||||
|
from odoo_openupgrade_wizard.cli_generate_module_analysis import (
|
||||||
|
generate_module_analysis,
|
||||||
|
)
|
||||||
from odoo_openupgrade_wizard.cli_get_code import get_code
|
from odoo_openupgrade_wizard.cli_get_code import get_code
|
||||||
from odoo_openupgrade_wizard.cli_init import init
|
from odoo_openupgrade_wizard.cli_init import init
|
||||||
from odoo_openupgrade_wizard.cli_install_from_csv import install_from_csv
|
from odoo_openupgrade_wizard.cli_install_from_csv import install_from_csv
|
||||||
|
|
@ -110,11 +113,12 @@ def main(ctx, env_folder, filestore_folder, log_level):
|
||||||
logger.debug("context %s: " % ctx.obj)
|
logger.debug("context %s: " % ctx.obj)
|
||||||
|
|
||||||
|
|
||||||
main.add_command(init)
|
|
||||||
main.add_command(get_code)
|
|
||||||
main.add_command(docker_build)
|
main.add_command(docker_build)
|
||||||
main.add_command(run)
|
|
||||||
main.add_command(install_from_csv)
|
|
||||||
main.add_command(upgrade)
|
|
||||||
main.add_command(execute_script_python)
|
main.add_command(execute_script_python)
|
||||||
main.add_command(execute_script_sql)
|
main.add_command(execute_script_sql)
|
||||||
|
main.add_command(generate_module_analysis)
|
||||||
|
main.add_command(get_code)
|
||||||
|
main.add_command(init)
|
||||||
|
main.add_command(install_from_csv)
|
||||||
|
main.add_command(run)
|
||||||
|
main.add_command(upgrade)
|
||||||
|
|
|
||||||
86
odoo_openupgrade_wizard/cli_generate_module_analysis.py
Normal file
86
odoo_openupgrade_wizard/cli_generate_module_analysis.py
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
import click
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
from odoo_openupgrade_wizard.cli_options import (
|
||||||
|
database_option,
|
||||||
|
get_migration_steps_from_options,
|
||||||
|
)
|
||||||
|
from odoo_openupgrade_wizard.configuration_version_dependant import (
|
||||||
|
generate_records,
|
||||||
|
get_upgrade_analysis_module,
|
||||||
|
)
|
||||||
|
from odoo_openupgrade_wizard.tools_odoo import kill_odoo, run_odoo
|
||||||
|
from odoo_openupgrade_wizard.tools_odoo_instance import OdooInstance
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.option(
|
||||||
|
"--last-step",
|
||||||
|
required=True,
|
||||||
|
prompt=True,
|
||||||
|
type=int,
|
||||||
|
help="Last step in witch the analysis will be generated",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--modules",
|
||||||
|
type=str,
|
||||||
|
help="Coma-separated list of modules to analysis."
|
||||||
|
" Let empty to analyse all the modules.",
|
||||||
|
)
|
||||||
|
@database_option
|
||||||
|
@click.pass_context
|
||||||
|
def generate_module_analysis(ctx, last_step, database, modules):
|
||||||
|
|
||||||
|
migration_steps = get_migration_steps_from_options(
|
||||||
|
ctx, last_step - 1, last_step
|
||||||
|
)
|
||||||
|
|
||||||
|
initial_step = migration_steps[0].copy()
|
||||||
|
final_step = migration_steps[1].copy()
|
||||||
|
|
||||||
|
if not database:
|
||||||
|
database = "%s__analysis__" % (
|
||||||
|
ctx.obj["config"]["project_name"].replace("-", "_"),
|
||||||
|
)
|
||||||
|
|
||||||
|
initial_database = "%s_%s" % (
|
||||||
|
database,
|
||||||
|
str(initial_step["release"]).replace(".", ""),
|
||||||
|
)
|
||||||
|
final_database = "%s_%s" % (
|
||||||
|
database,
|
||||||
|
str(final_step["release"]).replace(".", ""),
|
||||||
|
)
|
||||||
|
|
||||||
|
if not modules:
|
||||||
|
modules = "base"
|
||||||
|
|
||||||
|
# Force to be in openupgrade mode
|
||||||
|
initial_step["action"] = final_step["action"] = "upgrade"
|
||||||
|
|
||||||
|
try:
|
||||||
|
run_odoo(
|
||||||
|
ctx,
|
||||||
|
initial_step,
|
||||||
|
database=initial_database,
|
||||||
|
detached_container=False,
|
||||||
|
stop_after_init=True,
|
||||||
|
init=modules + "," + get_upgrade_analysis_module(initial_step),
|
||||||
|
)
|
||||||
|
|
||||||
|
run_odoo(
|
||||||
|
ctx,
|
||||||
|
initial_step,
|
||||||
|
database=initial_database,
|
||||||
|
detached_container=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
initial_instance = OdooInstance(ctx, initial_database)
|
||||||
|
generate_records(initial_instance, initial_step)
|
||||||
|
|
||||||
|
final_database = final_database
|
||||||
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
logger.info("Received Keyboard Interrupt or System Exiting...")
|
||||||
|
finally:
|
||||||
|
kill_odoo(ctx, initial_step)
|
||||||
|
kill_odoo(ctx, final_step)
|
||||||
|
|
@ -18,7 +18,7 @@ def step_option(function):
|
||||||
"--step",
|
"--step",
|
||||||
required=True,
|
required=True,
|
||||||
prompt=True,
|
prompt=True,
|
||||||
type=str,
|
type=int,
|
||||||
help="Migration step for which you want to perform the operation.",
|
help="Migration step for which you want to perform the operation.",
|
||||||
)(function)
|
)(function)
|
||||||
return function
|
return function
|
||||||
|
|
@ -27,7 +27,7 @@ def step_option(function):
|
||||||
def first_step_option(function):
|
def first_step_option(function):
|
||||||
function = click.option(
|
function = click.option(
|
||||||
"--first-step",
|
"--first-step",
|
||||||
type=str,
|
type=int,
|
||||||
help="First step for which to perform the operation",
|
help="First step for which to perform the operation",
|
||||||
)(function)
|
)(function)
|
||||||
return function
|
return function
|
||||||
|
|
@ -36,7 +36,7 @@ def first_step_option(function):
|
||||||
def last_step_option(function):
|
def last_step_option(function):
|
||||||
function = click.option(
|
function = click.option(
|
||||||
"--last-step",
|
"--last-step",
|
||||||
type=str,
|
type=int,
|
||||||
help="Last step for which to perform the operation",
|
help="Last step for which to perform the operation",
|
||||||
)(function)
|
)(function)
|
||||||
return function
|
return function
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
_ODOO_VERSION_TEMPLATES = [
|
_ODOO_VERSION_TEMPLATES = [
|
||||||
{
|
{
|
||||||
"release": 8.0,
|
"release": 8.0,
|
||||||
|
|
@ -126,3 +128,30 @@ def get_server_wide_modules_upgrade(migration_step: dict) -> str:
|
||||||
):
|
):
|
||||||
return ["openupgrade_framework"]
|
return ["openupgrade_framework"]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def get_upgrade_analysis_module(migration_step: dict) -> str:
|
||||||
|
""" return the upgrade_analysis module name"""
|
||||||
|
|
||||||
|
if migration_step["release"] >= 14.0:
|
||||||
|
# (Module in OCA/server-tools)
|
||||||
|
return "upgrade_analysis"
|
||||||
|
|
||||||
|
# (module in OCA/OpenUpgrade/odoo/addons/)
|
||||||
|
return "openupgrade_records"
|
||||||
|
|
||||||
|
|
||||||
|
def generate_records(odoo_instance, migration_step: dict):
|
||||||
|
logger.info(
|
||||||
|
"Generate Records in release %s ..."
|
||||||
|
" (It can take a while)" % (migration_step["release"])
|
||||||
|
)
|
||||||
|
if migration_step["release"] < 14.0:
|
||||||
|
wizard = odoo_instance.browse_by_create(
|
||||||
|
"openupgrade.generate.records.wizard", {}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
wizard = odoo_instance.browse_by_create(
|
||||||
|
"upgrade.generate.record.wizard", {}
|
||||||
|
)
|
||||||
|
wizard.generate()
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ PYTHON_REQUIREMENTS_TXT_TEMPLATE = """
|
||||||
{%- for python_librairy in python_libraries -%}
|
{%- for python_librairy in python_libraries -%}
|
||||||
{{ python_librairy }}
|
{{ python_librairy }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
odoorpc
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DEBIAN_REQUIREMENTS_TXT_TEMPLATE = """
|
DEBIAN_REQUIREMENTS_TXT_TEMPLATE = """
|
||||||
|
|
|
||||||
|
|
@ -148,13 +148,17 @@ def run_odoo(
|
||||||
):
|
):
|
||||||
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}.".format(
|
" in {action} mode. Demo Data is {demo_text}."
|
||||||
|
" {stop_text}. (Init : {init} ; Update : {update}".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"
|
action=migration_step["action"] == "update"
|
||||||
and "regular"
|
and "regular"
|
||||||
or "OpenUpgrade",
|
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 "",
|
||||||
|
init=init,
|
||||||
|
update=update,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
|
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ def get_odoo_url(ctx) -> str:
|
||||||
return "http://0.0.0.0:%d" % (ctx.obj["config"]["odoo_host_xmlrpc_port"])
|
return "http://0.0.0.0:%d" % (ctx.obj["config"]["odoo_host_xmlrpc_port"])
|
||||||
|
|
||||||
|
|
||||||
_ODOO_RPC_MAX_TRY = 10
|
_ODOO_RPC_MAX_TRY = 60
|
||||||
_ODOO_RPC_TIMEOUT = 60
|
_ODOO_RPC_TIMEOUT = 60
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,7 +22,11 @@ class OdooInstance:
|
||||||
# # TODO, improve me waith for response on http://localhost:port
|
# # TODO, improve me waith for response on http://localhost:port
|
||||||
# # with a time out
|
# # with a time out
|
||||||
# # the docker container take a little time to be up.
|
# # the docker container take a little time to be up.
|
||||||
time.sleep(60)
|
# time.sleep(60)
|
||||||
|
port = ctx.obj["config"]["odoo_host_xmlrpc_port"]
|
||||||
|
logger.info(
|
||||||
|
"Connect to Odoo instance via odoorpc (Port %s)... " % port
|
||||||
|
)
|
||||||
|
|
||||||
for x in range(1, _ODOO_RPC_MAX_TRY + 1):
|
for x in range(1, _ODOO_RPC_MAX_TRY + 1):
|
||||||
# Connection
|
# Connection
|
||||||
|
|
@ -30,14 +34,14 @@ class OdooInstance:
|
||||||
rpc_connexion = odoorpc.ODOO(
|
rpc_connexion = odoorpc.ODOO(
|
||||||
"0.0.0.0",
|
"0.0.0.0",
|
||||||
"jsonrpc",
|
"jsonrpc",
|
||||||
port=ctx.obj["config"]["odoo_host_xmlrpc_port"],
|
port=port,
|
||||||
timeout=_ODOO_RPC_TIMEOUT,
|
timeout=_ODOO_RPC_TIMEOUT,
|
||||||
)
|
)
|
||||||
# connexion is OK
|
# connexion is OK
|
||||||
break
|
break
|
||||||
except (socket.gaierror, socket.error) as e:
|
except (socket.gaierror, socket.error) as e:
|
||||||
if x < _ODOO_RPC_MAX_TRY:
|
if x < _ODOO_RPC_MAX_TRY:
|
||||||
logger.info(
|
logger.debug(
|
||||||
"%d/%d Unable to connect to the server."
|
"%d/%d Unable to connect to the server."
|
||||||
" Retrying in 1 second ..." % (x, _ODOO_RPC_MAX_TRY)
|
" Retrying in 1 second ..." % (x, _ODOO_RPC_MAX_TRY)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user