forked from maclarensg/odoo_module_install_script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_module.py
More file actions
executable file
·62 lines (46 loc) · 1.76 KB
/
install_module.py
File metadata and controls
executable file
·62 lines (46 loc) · 1.76 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
#!/usr/bin/env python
import sys
import ConfigParser
from pprint import pprint
import odoorpc
# main
def main(list):
# Read configurations and parse them to variables
Config = ConfigParser.ConfigParser()
Config.read("./config.ini")
host = Config.get('host', 'host')
port = int(Config.get('host', 'port'))
db_name = Config.get('database', 'db_name')
user = Config.get('database', 'user')
passwd = Config.get('database', 'passwd')
# Prepare the connection to the server
odoo = odoorpc.ODOO('localhost', port=8069)
# Check if db_name exist in db list
if db_name not in odoo.db.list():
sys.exit("DB %s not found in db list" % db_name)
# Login
odoo.login(db_name, user, passwd)
# Module is 'ir.module.module'
Module = odoo.env['ir.module.module']
# Iterate the list of items to install
for item in list:
# Get the module ids by name
module_ids = Module.search([['name', '=', item]])
# there should be 1 module in module_ids, but iterate for each module object
for module in Module.browse(module_ids):
if module.state == 'installed':
# If installed, just print that it has install
print "%s has already been installed." % module.name
else:
# Otherwise, install it
sys.stdout.write("Installing %s ... " % module.name)
module.button_immediate_install()
print "Done."
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.exit("Usage:\n./install_module.py <module 1> <module 2> .. <module n>")
# Get module list from argv
modules_list = sys.argv
modules_list.pop(0)
# call main
main(modules_list)