Skip to content

Commit

Permalink
[ADD] click-odoo-update --only-compute-hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-software-de committed Nov 25, 2024
1 parent 8329fe7 commit 8d7d2fb
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions click_odoo_contrib/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -311,6 +319,7 @@ def OdooEnvironmentWithUpdate(database, ctx, **kwargs):
watcher,
ctx.params["list_only"],
ignore_addons,
ctx.params["only_compute_hashes"],
)
finally:
if watcher:
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
68 changes: 66 additions & 2 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit 8d7d2fb

Please sign in to comment.