|
@@ -7,10 +7,13 @@ from api.utils.docker_api import (
|
|
|
get_internal_ip,
|
|
|
execute_command,
|
|
|
run_container,
|
|
|
+ start_container,
|
|
|
+ stop_container,
|
|
|
copy_in
|
|
|
)
|
|
|
-from api.utils.logger import info
|
|
|
+from api.utils.git_api import clone_repo
|
|
|
from api.utils.command import execute
|
|
|
+from api.utils.logger import info
|
|
|
import os
|
|
|
import socket
|
|
|
import time
|
|
@@ -206,7 +209,50 @@ def get_odoo_internal_ip(name=None):
|
|
|
'''
|
|
|
'''
|
|
|
def install_module(system_name=None, module_name=None):
|
|
|
- if not system_name or not module_name:
|
|
|
- return False
|
|
|
+ if not system_name:
|
|
|
+ return {'error': 'system name is required'}
|
|
|
+
|
|
|
+ if not module_name:
|
|
|
+ return {'error': 'module name is required'}
|
|
|
+
|
|
|
+ # 1. check system path
|
|
|
+ system_path = os.path.join(settings.ODOO_ROOT_PATH, system_name)
|
|
|
+
|
|
|
+ if not os.path.exists(system_path):
|
|
|
+ return {'error': 'system path not exists'}
|
|
|
+
|
|
|
+ # 2. stop system container
|
|
|
+ stopped = stop_container(system_name)
|
|
|
+
|
|
|
+ if not stopped:
|
|
|
+ return {'error': 'cannot stop system'}
|
|
|
+
|
|
|
+ # 3. check module path and remove it
|
|
|
+ module_path = os.path.join(system_path, 'custom-addons', module_name)
|
|
|
+
|
|
|
+ if os.path.exists(module_path):
|
|
|
+ execute(['rm', '-Rf', module_path])
|
|
|
|
|
|
-
|
|
|
+ # 4. clone repo
|
|
|
+ cloned = clone_repo(module_name, os.path.join(system_path, 'custom/addons'))
|
|
|
+
|
|
|
+ if not cloned:
|
|
|
+ return {'error': 'cannot clone repo'}
|
|
|
+
|
|
|
+ # 5. start system container
|
|
|
+ started = start_container(system_name)
|
|
|
+
|
|
|
+ if not started:
|
|
|
+ return {'error': 'cannot start system'}
|
|
|
+
|
|
|
+ return {'result': '%s installed' % module_name}
|
|
|
+
|
|
|
+'''
|
|
|
+'''
|
|
|
+def up():
|
|
|
+ pass
|
|
|
+
|
|
|
+'''
|
|
|
+'''
|
|
|
+def kill():
|
|
|
+ pass
|