From d890a460ea9ae5fb5a7fdd25494838145455da76 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 1 Mar 2024 15:21:34 +0100 Subject: [PATCH 1/2] [IMP] Harmonize run and upgrade cli command. Allow to call command with argument --with-demo / --without-demo like in install-from-csv. For that purpose, create a new decorator. [REF] Change the default of install-from-csv to harmonize. (allways False) --- odoo_openupgrade_wizard/cli/cli_install_from_csv.py | 7 ++----- odoo_openupgrade_wizard/cli/cli_options.py | 9 +++++++++ odoo_openupgrade_wizard/cli/cli_run.py | 13 ++++++++++++- odoo_openupgrade_wizard/cli/cli_upgrade.py | 5 ++++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/odoo_openupgrade_wizard/cli/cli_install_from_csv.py b/odoo_openupgrade_wizard/cli/cli_install_from_csv.py index 1d06658..40eb2e5 100644 --- a/odoo_openupgrade_wizard/cli/cli_install_from_csv.py +++ b/odoo_openupgrade_wizard/cli/cli_install_from_csv.py @@ -3,6 +3,7 @@ from loguru import logger from odoo_openupgrade_wizard.cli.cli_options import ( database_option, + demo_option, get_migration_step_from_options, ) from odoo_openupgrade_wizard.tools.tools_odoo import ( @@ -16,11 +17,7 @@ from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database @click.command() @database_option -@click.option( - "--with-demo/--whitout-demo", - default=True, - help="Create database with or without demo data.", -) +@demo_option @click.pass_context def install_from_csv(ctx, database, with_demo): migration_step = get_migration_step_from_options(ctx, 1) diff --git a/odoo_openupgrade_wizard/cli/cli_options.py b/odoo_openupgrade_wizard/cli/cli_options.py index 7efcb19..4e46ab7 100644 --- a/odoo_openupgrade_wizard/cli/cli_options.py +++ b/odoo_openupgrade_wizard/cli/cli_options.py @@ -44,6 +44,15 @@ def last_step_option(function): return function +def demo_option(function): + function = click.option( + "--with-demo/--without-demo", + default=False, + help="Create database with or without demo data.", + )(function) + return function + + def database_option(function): function = click.option( "-d", diff --git a/odoo_openupgrade_wizard/cli/cli_run.py b/odoo_openupgrade_wizard/cli/cli_run.py index 6d06dc1..b2858fb 100644 --- a/odoo_openupgrade_wizard/cli/cli_run.py +++ b/odoo_openupgrade_wizard/cli/cli_run.py @@ -3,6 +3,7 @@ from loguru import logger from odoo_openupgrade_wizard.cli.cli_options import ( database_option, + demo_option, get_migration_step_from_options, step_option, ) @@ -13,6 +14,7 @@ from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database @click.command() @step_option @database_option +@demo_option @click.option( "--stop-after-init", is_flag=True, @@ -36,7 +38,15 @@ from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database " Let empty to use the defaut execution of the migration step.", ) @click.pass_context -def run(ctx, step, database, stop_after_init, init_modules, execution_context): +def run( + ctx, + step, + database, + with_demo, + stop_after_init, + init_modules, + execution_context, +): migration_step = get_migration_step_from_options(ctx, step) ensure_database(ctx, database, state="present") try: @@ -47,6 +57,7 @@ def run(ctx, step, database, stop_after_init, init_modules, execution_context): detached_container=not stop_after_init, init=init_modules, stop_after_init=stop_after_init, + demo=with_demo, execution_context=execution_context, ) if not stop_after_init: diff --git a/odoo_openupgrade_wizard/cli/cli_upgrade.py b/odoo_openupgrade_wizard/cli/cli_upgrade.py index 4989abb..55f0481 100644 --- a/odoo_openupgrade_wizard/cli/cli_upgrade.py +++ b/odoo_openupgrade_wizard/cli/cli_upgrade.py @@ -3,6 +3,7 @@ from loguru import logger from odoo_openupgrade_wizard.cli.cli_options import ( database_option_required, + demo_option, first_step_option, get_migration_steps_from_options, last_step_option, @@ -21,8 +22,9 @@ from odoo_openupgrade_wizard.tools.tools_postgres import ( @first_step_option @last_step_option @database_option_required +@demo_option @click.pass_context -def upgrade(ctx, first_step, last_step, database): +def upgrade(ctx, first_step, last_step, database, with_demo): migration_steps = get_migration_steps_from_options( ctx, first_step, last_step ) @@ -36,6 +38,7 @@ def upgrade(ctx, first_step, last_step, database): detached_container=False, update="all", stop_after_init=True, + demo=with_demo, ) except (KeyboardInterrupt, SystemExit): logger.info("Received Keyboard Interrupt or System Exiting...") From dbdf5929902f9bf389e9b0a6a8b3cb47ec74d81d Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 1 Mar 2024 15:36:13 +0100 Subject: [PATCH 2/2] [IMP] 'run' cli command. Add '--update-modules' option --- odoo_openupgrade_wizard/cli/cli_run.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/odoo_openupgrade_wizard/cli/cli_run.py b/odoo_openupgrade_wizard/cli/cli_run.py index b2858fb..8c507a6 100644 --- a/odoo_openupgrade_wizard/cli/cli_run.py +++ b/odoo_openupgrade_wizard/cli/cli_run.py @@ -29,6 +29,12 @@ from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database type=str, help="List of modules to install. Equivalent to -i odoo options.", ) +@click.option( + "-u", + "--update-modules", + type=str, + help="List of modules to update. Equivalent to -u odoo options.", +) @click.option( "-e", "--execution-context", @@ -45,6 +51,7 @@ def run( with_demo, stop_after_init, init_modules, + update_modules, execution_context, ): migration_step = get_migration_step_from_options(ctx, step) @@ -56,6 +63,7 @@ def run( database=database, detached_container=not stop_after_init, init=init_modules, + update=update_modules, stop_after_init=stop_after_init, demo=with_demo, execution_context=execution_context,