-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_modules.py
More file actions
72 lines (55 loc) · 2.12 KB
/
Copy pathinstall_modules.py
File metadata and controls
72 lines (55 loc) · 2.12 KB
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
#!/bin/python
import os
from proteus import config, Model, Wizard, Report
DB_NAME = os.environ.get('DATABASE_NAME')
CONFIG_FILE_PATH = '/tryton/config.ini'
INSTALLED = []
FAILED = []
SKIPPED = []
BLACKLIST = ["product_classification_taxonomic",
"purchase_request"]
config = config.set_trytond(DB_NAME, config_file=CONFIG_FILE_PATH)
def main():
Module = Model.get("ir.module")
not_installed_modules = Module.find([("state", "!=", "installed")])
for not_installed_module in not_installed_modules:
# double check in case this module was installed as dependency
if not_installed_module.state != u"installed":
install_module(not_installed_module)
print 'Done. \n' \
'Installed modules: \n%s\n' \
'Skipped modules: \n%s\n' \
'Failed modules: \n%s\n' % (
'\n'.join(INSTALLED) or '-',
'\n'.join(SKIPPED) or '-',
'\n'.join(FAILED) or '-'
)
def install_module(module):
"""Lookup uninstalled dependencies and recuresively install them."""
if module.name in BLACKLIST:
# print("[!] Skipped installation of blacklisted module {}".format(module.name))
SKIPPED.append(module.name)
return False
# install missing dependencies recursively
missing_dependencies = [m for m in module.parents if m.state != u"installed"]
for missing_dependency in missing_dependencies:
if missing_dependency.name in FAILED:
return False
if not install_module(missing_dependency):
print("[!] Skipped installation of {} because of failed dependencies".format(module.name))
return False
# mark module to install and run installation wizard
# print("Installing module {}".format(module.name))
try:
module.click("install")
Wizard('ir.module.install_upgrade').execute('upgrade')
except Exception as e:
# print("[!] Failed to install {}".format(module.name))
# print(e.message)
FAILED.append(module.name)
return False
else:
INSTALLED.append(module.name)
return True
if __name__ == "__main__":
main()