Skip to content

Commit e7a6e91

Browse files
committed
[IMP] util.modules: fine-tuning control of the auto-install behavior
Deprecate the `UPG_NO_AUTOINSTALL` environmnet variable in favor the new `UPG_AUTOINSTALL` one, which allow to fully deactivate the installation of the auto-install modules. Previsouly, the "link modules" (auto install modules that are in the "Hidden" category) were still auto-installed, even when the `UPG_NO_AUTOINSTALL` flag was set. With the new `UPG_AUTOINSTALL` env variable, we can now skip their auto-install. The accepted values are: - all: install all the auto-install modules (that should be installed) - only_link_modules: only consider the link modules - none: do not auto-install any auto-install modules automatically Part-of: #162 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 0f91c0c commit e7a6e91

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/util/modules.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,31 @@
5151
from .records import ref, remove_menus, remove_records, remove_view, replace_record_references_batch
5252

5353
INSTALLED_MODULE_STATES = ("installed", "to install", "to upgrade")
54-
NO_AUTOINSTALL = str2bool(os.getenv("UPG_NO_AUTOINSTALL", "0")) if version_gte("15.0") else False
5554
_logger = logging.getLogger(__name__)
5655

56+
if version_gte("15.0"):
57+
AUTO_INSTALL = os.getenv("UPG_AUTOINSTALL")
58+
_NO_AUTOINSTALL = os.getenv("UPG_NO_AUTOINSTALL")
59+
if AUTO_INSTALL:
60+
if _NO_AUTOINSTALL:
61+
_logger.info("Ignoring the deprecated `UPG_NO_AUTOINSTALL` env variable as `UPG_AUTOINSTALL` is also set.")
62+
elif _NO_AUTOINSTALL:
63+
AUTO_INSTALL = "only_link_modules" if str2bool(_NO_AUTOINSTALL) else "all"
64+
# TODO add link to doc
65+
_logger.warning(
66+
"Usage of the `UPG_NO_AUTOINSTALL` environment variable is deprecated. Please use `UPG_AUTOINSTALL=%s`.",
67+
AUTO_INSTALL,
68+
)
69+
else:
70+
AUTO_INSTALL = "all"
71+
else:
72+
AUTO_INSTALL = "all"
73+
74+
if AUTO_INSTALL not in ("all", "only_link_modules", "none"):
75+
raise ValueError("Invalid value for the `UPG_AUTOINSTALL` environment variable: {!r}".format(AUTO_INSTALL))
76+
77+
_logger.info("module auto-install strategy: %s", AUTO_INSTALL)
78+
5779
# python3 shims
5880
try:
5981
basestring # noqa: B018
@@ -525,9 +547,10 @@ def force_install_module(cr, module, if_installed=None):
525547
)
526548

527549
states = dict(cr.fetchall())
528-
# auto_install modules...
529550
toinstall = [m for m in states if states[m] == "to install"]
530-
if toinstall:
551+
552+
# auto_install modules...
553+
if AUTO_INSTALL in ("all", "only_link_modules") and toinstall:
531554
# Same algo as ir.module.module.button_install(): https://git.io/fhCKd
532555
dep_match = ""
533556
if column_exists(cr, "ir_module_module_dependency", "auto_install_required"):
@@ -555,7 +578,7 @@ def force_install_module(cr, module, if_installed=None):
555578
"""
556579

557580
cat_match = ""
558-
if NO_AUTOINSTALL:
581+
if AUTO_INSTALL == "only_link_modules":
559582
# even if we skip auto installs, we still need to auto install the real link-modules.
560583
# those are in the "Hidden" category
561584
hidden = ref(cr, "base.module_category_hidden")
@@ -679,6 +702,9 @@ def module_auto_install(cr, module, auto_install):
679702

680703
def trigger_auto_install(cr, module):
681704
_assert_modules_exists(cr, module)
705+
if AUTO_INSTALL == "none":
706+
return False
707+
682708
dep_match = "true"
683709
if column_exists(cr, "ir_module_module_dependency", "auto_install_required"):
684710
dep_match = "d.auto_install_required = true"
@@ -705,7 +731,7 @@ def trigger_auto_install(cr, module):
705731
"""
706732

707733
cat_match = "true"
708-
if NO_AUTOINSTALL:
734+
if AUTO_INSTALL == "only_link_modules":
709735
# even if we skip auto installs, we still need to auto install the real link-modules.
710736
# those are in the "Hidden" category
711737
hidden = ref(cr, "base.module_category_hidden")

0 commit comments

Comments
 (0)