forked from OCA/server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch.py
91 lines (71 loc) · 2.98 KB
/
patch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import modules
from odoo.tools import config
_logger = logging.getLogger(__name__)
_original_load_manifest = modules.module.load_manifest
def _get_modules_dict_auto_install_config(config_value):
"""Given a configuration parameter name, return a dict of
{module_name: modules_list or False}
if the odoo.cfg file contains
modules_auto_install_enabled =
web_responsive:web,
base_technical_features:,
point_of_sale:sale/purchase,
account_usability
>>> split_strip('modules_auto_install_enabled')
{
'web_responsive': ['web'],
'base_technical_features': [],
'point_of_sale': ['sale', 'purchase'],
'account_usability': False,
}
"""
res = {}
config_value = (config_value or "").strip(" ,")
config_list = [x.strip() for x in config_value.split(",")]
for item in config_list:
if ":" in item:
res[item.split(":")[0]] = (
item.split(":")[1] and item.split(":")[1].split("/") or []
)
else:
res[item] = True
return res
def _overload_load_manifest(module, mod_path=None):
res = _original_load_manifest(module, mod_path=None)
auto_install = res.get("auto_install", False)
modules_auto_install_enabled_dict = _get_modules_dict_auto_install_config(
config.get("modules_auto_install_enabled")
)
modules_auto_install_disabled_dict = _get_modules_dict_auto_install_config(
config.get("modules_auto_install_disabled")
)
if auto_install and module in modules_auto_install_disabled_dict.keys():
_logger.info("Module '%s' has been marked as NOT auto installable." % module)
res["auto_install"] = False
if not auto_install and module in modules_auto_install_enabled_dict.keys():
specific_dependencies = modules_auto_install_enabled_dict.get(module)
if type(specific_dependencies) is bool:
# Classical case
_logger.info("Module '%s' has been marked as auto installable." % module)
res["auto_install"] = set(res["depends"])
else:
if specific_dependencies:
_logger.info(
"Module '%s' has been marked as auto installable if '%s' are installed"
% (module, ",".join(specific_dependencies))
)
else:
_logger.info(
"Module '%s' has been marked as auto installable in ALL CASES."
% module
)
res["auto_install"] = set(specific_dependencies)
return res
def post_load():
_logger.info("Applying patch module_change_auto_intall ...")
modules.module.load_manifest = _overload_load_manifest
modules.load_manifest = _overload_load_manifest