[ADD] upgrade command
This commit is contained in:
parent
fa5d9913a2
commit
5bcd02b485
|
|
@ -10,6 +10,7 @@ from odoo_openupgrade_wizard.cli_docker_build import docker_build
|
||||||
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_run import run
|
from odoo_openupgrade_wizard.cli_run import run
|
||||||
|
from odoo_openupgrade_wizard.cli_upgrade import upgrade
|
||||||
from odoo_openupgrade_wizard.tools_system import ensure_folder_exists
|
from odoo_openupgrade_wizard.tools_system import ensure_folder_exists
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -94,3 +95,4 @@ main.add_command(init)
|
||||||
main.add_command(get_code)
|
main.add_command(get_code)
|
||||||
main.add_command(docker_build)
|
main.add_command(docker_build)
|
||||||
main.add_command(run)
|
main.add_command(run)
|
||||||
|
main.add_command(upgrade)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from odoo_openupgrade_wizard.cli_options import (
|
||||||
get_odoo_versions_from_options,
|
get_odoo_versions_from_options,
|
||||||
releases_options,
|
releases_options,
|
||||||
)
|
)
|
||||||
from odoo_openupgrade_wizard.tools_docker import get_docker_client
|
from odoo_openupgrade_wizard.tools_docker import build_image
|
||||||
from odoo_openupgrade_wizard.tools_odoo import (
|
from odoo_openupgrade_wizard.tools_odoo import (
|
||||||
get_docker_image_tag,
|
get_docker_image_tag,
|
||||||
get_odoo_env_path,
|
get_odoo_env_path,
|
||||||
|
|
@ -18,15 +18,13 @@ from odoo_openupgrade_wizard.tools_odoo import (
|
||||||
def docker_build(ctx, releases):
|
def docker_build(ctx, releases):
|
||||||
"""Build Odoo Docker Images. (One image per release)"""
|
"""Build Odoo Docker Images. (One image per release)"""
|
||||||
|
|
||||||
docker_client = get_docker_client()
|
|
||||||
|
|
||||||
for odoo_version in get_odoo_versions_from_options(ctx, releases):
|
for odoo_version in get_odoo_versions_from_options(ctx, releases):
|
||||||
logger.info(
|
logger.info(
|
||||||
"Building Odoo docker image for release '%s'. "
|
"Building Odoo docker image for release '%s'. "
|
||||||
"This can take a while..." % (odoo_version["release"])
|
"This can take a while..." % (odoo_version["release"])
|
||||||
)
|
)
|
||||||
image = docker_client.images.build(
|
image = build_image(
|
||||||
path=str(get_odoo_env_path(ctx, odoo_version)),
|
str(get_odoo_env_path(ctx, odoo_version)),
|
||||||
tag=get_docker_image_tag(ctx, odoo_version),
|
get_docker_image_tag(ctx, odoo_version),
|
||||||
)
|
)
|
||||||
logger.info("Docker Image build. '%s'" % image[0].tags[0])
|
logger.info("Docker Image build. '%s'" % image[0].tags[0])
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ def releases_options(function):
|
||||||
|
|
||||||
def step_option(function):
|
def step_option(function):
|
||||||
function = click.option(
|
function = click.option(
|
||||||
|
"-s",
|
||||||
"--step",
|
"--step",
|
||||||
required=True,
|
required=True,
|
||||||
prompt=True,
|
prompt=True,
|
||||||
|
|
@ -22,8 +23,27 @@ def step_option(function):
|
||||||
return function
|
return function
|
||||||
|
|
||||||
|
|
||||||
|
def first_step_option(function):
|
||||||
|
function = click.option(
|
||||||
|
"--first-step",
|
||||||
|
type=str,
|
||||||
|
help="First step for which to perform the operation",
|
||||||
|
)(function)
|
||||||
|
return function
|
||||||
|
|
||||||
|
|
||||||
|
def last_step_option(function):
|
||||||
|
function = click.option(
|
||||||
|
"--last-step",
|
||||||
|
type=str,
|
||||||
|
help="Last step for which to perform the operation",
|
||||||
|
)(function)
|
||||||
|
return function
|
||||||
|
|
||||||
|
|
||||||
def database_option(function):
|
def database_option(function):
|
||||||
function = click.option(
|
function = click.option(
|
||||||
|
"-d",
|
||||||
"--database",
|
"--database",
|
||||||
type=str,
|
type=str,
|
||||||
help="Odoo Database for which you want to perform the operation.",
|
help="Odoo Database for which you want to perform the operation.",
|
||||||
|
|
@ -31,6 +51,18 @@ def database_option(function):
|
||||||
return function
|
return function
|
||||||
|
|
||||||
|
|
||||||
|
def database_option_required(function):
|
||||||
|
function = click.option(
|
||||||
|
"-d",
|
||||||
|
"--database",
|
||||||
|
required=True,
|
||||||
|
prompt=True,
|
||||||
|
type=str,
|
||||||
|
help="Odoo Database for which you want to perform the operation.",
|
||||||
|
)(function)
|
||||||
|
return function
|
||||||
|
|
||||||
|
|
||||||
def get_odoo_versions_from_options(ctx, releases_arg):
|
def get_odoo_versions_from_options(ctx, releases_arg):
|
||||||
|
|
||||||
if not releases_arg:
|
if not releases_arg:
|
||||||
|
|
@ -51,3 +83,22 @@ def get_migration_step_from_options(ctx, step_arg):
|
||||||
return migration_step
|
return migration_step
|
||||||
# TODO, improve exception
|
# TODO, improve exception
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
|
def get_migration_steps_from_options(ctx, first_step_arg, last_step_arg):
|
||||||
|
result = []
|
||||||
|
if first_step_arg:
|
||||||
|
first_step = float(first_step_arg)
|
||||||
|
else:
|
||||||
|
first_step = ctx.obj["config"]["migration_steps"][0]["name"]
|
||||||
|
if last_step_arg:
|
||||||
|
last_step = float(last_step_arg)
|
||||||
|
else:
|
||||||
|
last_step = ctx.obj["config"]["migration_steps"][-1]["name"]
|
||||||
|
for migration_step in ctx.obj["config"]["migration_steps"]:
|
||||||
|
if migration_step["name"] in list(range(first_step, last_step + 1)):
|
||||||
|
result.append(migration_step.copy())
|
||||||
|
if not result:
|
||||||
|
# TODO, improve exception
|
||||||
|
raise Exception
|
||||||
|
return result
|
||||||
|
|
|
||||||
36
odoo_openupgrade_wizard/cli_upgrade.py
Normal file
36
odoo_openupgrade_wizard/cli_upgrade.py
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import click
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
from odoo_openupgrade_wizard.cli_options import (
|
||||||
|
database_option_required,
|
||||||
|
first_step_option,
|
||||||
|
get_migration_steps_from_options,
|
||||||
|
last_step_option,
|
||||||
|
)
|
||||||
|
from odoo_openupgrade_wizard.tools_odoo import kill_odoo, run_odoo
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@first_step_option
|
||||||
|
@last_step_option
|
||||||
|
@database_option_required
|
||||||
|
@click.pass_context
|
||||||
|
def upgrade(ctx, first_step, last_step, database):
|
||||||
|
|
||||||
|
migration_steps = get_migration_steps_from_options(
|
||||||
|
ctx, first_step, last_step
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
for migration_step in migration_steps:
|
||||||
|
run_odoo(
|
||||||
|
ctx,
|
||||||
|
migration_step,
|
||||||
|
database=database,
|
||||||
|
detached_container=False,
|
||||||
|
update="all",
|
||||||
|
stop_after_init=True,
|
||||||
|
)
|
||||||
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
logger.info("Received Keyboard Interrupt or System Exiting...")
|
||||||
|
finally:
|
||||||
|
kill_odoo(ctx, migration_step)
|
||||||
|
|
@ -6,6 +6,16 @@ def get_docker_client():
|
||||||
return docker.from_env()
|
return docker.from_env()
|
||||||
|
|
||||||
|
|
||||||
|
def build_image(path, tag):
|
||||||
|
logger.info("Building image named %s with file %s..." % (tag, path))
|
||||||
|
|
||||||
|
docker_client = get_docker_client()
|
||||||
|
return docker_client.images.build(
|
||||||
|
path=path,
|
||||||
|
tag=tag,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_container(
|
def run_container(
|
||||||
image_name,
|
image_name,
|
||||||
container_name,
|
container_name,
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ def generate_odoo_command(
|
||||||
# TODO, make it dynamic
|
# TODO, make it dynamic
|
||||||
addons_path = get_odoo_addons_path(ctx, Path("/odoo_env"), migration_step)
|
addons_path = get_odoo_addons_path(ctx, Path("/odoo_env"), migration_step)
|
||||||
database_cmd = database and "--database %s" % database or ""
|
database_cmd = database and "--database %s" % database or ""
|
||||||
update_cmd = update and "--update_%s" % update or ""
|
update_cmd = update and "--update %s" % update or ""
|
||||||
init_cmd = init and "--init %s" % init or ""
|
init_cmd = init and "--init %s" % init or ""
|
||||||
stop_after_init_cmd = stop_after_init and "--stop-after-init" or ""
|
stop_after_init_cmd = stop_after_init and "--stop-after-init" or ""
|
||||||
shell_cmd = shell and "shell" or ""
|
shell_cmd = shell and "shell" or ""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user