diff --git a/README.rst b/README.rst index cc1d02c..4ea45d0 100644 --- a/README.rst +++ b/README.rst @@ -294,6 +294,9 @@ click-odoo-update (stable) update process. Default: 0 (disabled). --list-only Log the list of addons to update without actually updating them. + --only-compute-hashes Initialise hash values of installed addons. + Use this when you are sure all your addons are up-to-date + and you don't want to run `click-odoo-update --update-all`. --help Show this message and exit. Useful links @@ -331,6 +334,7 @@ Contributors: - Laurent Mignon (ACSONE_) - Lois Rilo (ForgeFlow_) - Dmitry Voronin +- Michael Tietz (MT Software) .. _ACSONE: https://acsone.eu .. _Tecnativa: https://tecnativa.com diff --git a/click_odoo_contrib/update.py b/click_odoo_contrib/update.py index 2369af5..a7c014e 100644 --- a/click_odoo_contrib/update.py +++ b/click_odoo_contrib/update.py @@ -265,9 +265,17 @@ def _update_db( watcher=None, list_only=False, ignore_addons=None, + only_compute_hashes=False, ): conn = odoo.sql_db.db_connect(database) with conn.cursor() as cr, advisory_lock(cr, "click-odoo-update/" + database): + if only_compute_hashes: + _save_installed_checksums(cr, ignore_addons) + _logger.info( + "Only computed and stored module hashes, update is not performed." + ) + return + _update_db_nolock( conn, database, @@ -311,6 +319,7 @@ def OdooEnvironmentWithUpdate(database, ctx, **kwargs): watcher, ctx.params["list_only"], ignore_addons, + ctx.params["only_compute_hashes"], ) finally: if watcher: @@ -362,6 +371,15 @@ def OdooEnvironmentWithUpdate(database, ctx, **kwargs): is_flag=True, help="Log the list of addons to update without actually updating them.", ) +@click.option( + "--only-compute-hashes", + is_flag=True, + help=( + "Initialise hash values of installed addons. " + "Use this when you are sure all your addons are up-to-date " + "and you don't want to run `click-odoo-update --update-all`." + ), +) def main( env, i18n_overwrite, @@ -371,6 +389,7 @@ def main( list_only, ignore_addons, ignore_core_addons, + only_compute_hashes, ): """Update an Odoo database (odoo -u), automatically detecting addons to update based on a hash of their file content, compared diff --git a/tests/test_update.py b/tests/test_update.py index 34b0f13..5b784c7 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -10,7 +10,11 @@ from click.testing import CliRunner from click_odoo import OdooEnvironment, odoo, odoo_bin -from click_odoo_contrib.update import _load_installed_checksums, main +from click_odoo_contrib.update import ( + _load_installed_checksums, + main, + PARAM_INSTALLED_CHECKSUMS, +) # this extends the addons path of the odoodb and odoocfg fixtures # we use the v1 dir, so the first install work (since it's only since version 12 @@ -51,10 +55,11 @@ def _check_expected(odoodb, v): def _install_one(odoodb, v): + addon_name = "addon_app" cmd = [ odoo_bin, "--addons-path", - _addons_path("v1"), + _addons_path(v), "-d", odoodb, "-i", @@ -95,6 +100,24 @@ def _update_list(odoodb, v): subprocess.check_call(cmd) +def _only_compute_hashes(odoodb, v, ignore_addons=None, ignore_core_addons=None): + cmd = [ + sys.executable, + "-m", + "click_odoo_contrib.update", + "--addons-path", + _addons_path(v), + "-d", + odoodb, + "--only-compute-hashes", + ] + if ignore_addons: + cmd += ["--ignore-addons", ignore_addons] + if ignore_core_addons: + cmd += ["--ignore-core-addons"] + subprocess.check_call(cmd) + + def test_update(odoodb): _install_one(odoodb, "v1") _check_expected(odoodb, "v1") @@ -170,3 +193,44 @@ def test_parallel_watcher(odoodb): ] subprocess.check_call(cmd) # TODO Test an actual lock + + +def test_only_compute_hashes(odoodb): + version = "v3" + conn = odoo.sql_db.db_connect(odoodb) + with conn.cursor() as cr: + cr.execute( + "DELETE from ir_config_parameter where key=%s", (PARAM_INSTALLED_CHECKSUMS,) + ) + + _install_one(odoodb, version) + with OdooEnvironment(odoodb) as env: + checksums = _load_installed_checksums(env.cr) + assert "base" not in checksums + assert "addon_app" not in checksums + assert "addon_d1" not in checksums + assert "addon_d2" not in checksums + + _only_compute_hashes(odoodb, version, "addon_d1,addon_d2", True) + with OdooEnvironment(odoodb) as env: + checksums = _load_installed_checksums(env.cr) + assert "base" not in checksums + assert "addon_app" in checksums + assert "addon_d1" not in checksums + assert "addon_d2" not in checksums + + _only_compute_hashes(odoodb, version, None, True) + with OdooEnvironment(odoodb) as env: + checksums = _load_installed_checksums(env.cr) + assert "base" not in checksums + assert "addon_app" in checksums + assert "addon_d1" in checksums + assert "addon_d2" in checksums + + _only_compute_hashes(odoodb, version) + with OdooEnvironment(odoodb) as env: + checksums = _load_installed_checksums(env.cr) + assert "base" in checksums + assert "addon_app" in checksums + assert "addon_d1" in checksums + assert "addon_d2" in checksums