in modular_api/services/install_service.py [0:0]
def uninstall_module(module_name):
"""
:param module_name: the name to the module to uninstalling
:return: none
"""
_LOG.info(f"Going to delete the '{module_name}' module")
m3_modular_admin_dir, _ = os.path.split(os.path.dirname(__file__))
module_descriptor_path = os.path.join(
m3_modular_admin_dir, MODULES_DIR,
module_name, API_MODULE_FILE)
if not os.path.isfile(module_descriptor_path):
incorrect_path_message = 'Provided path is incorrect or does ' \
'not contain api_module.json file'
_LOG.error(incorrect_path_message)
raise ModularApiBadRequestException(incorrect_path_message)
with open(module_descriptor_path) as file:
api_module_config = json.load(file)
check_uninstall(api_module_config)
if not all(key in api_module_config.keys()
for key in DESCRIPTOR_REQUIRED_KEYS):
descriptor_key_absence_message = \
f'Descriptor file must contains the following keys: ' \
f'{", ".join(DESCRIPTOR_REQUIRED_KEYS)}'
_LOG.error(descriptor_key_absence_message)
sys.exit(descriptor_key_absence_message)
web_service_cmd_base = os.path.join(MODULAR_ADMIN_ROOT_PATH,
'web_service',
'commands_base.json')
mount_point = api_module_config[MOUNT_POINT_KEY]
with open(web_service_cmd_base) as file:
web_service_content = json.load(file)
_LOG.info(f'Deleting the {mount_point} mount point from metadata')
web_service_content.pop(mount_point, None)
with open(web_service_cmd_base, 'w') as file:
json.dump(web_service_content, file, indent=2)
remove_tree(
os.path.join(MODULAR_ADMIN_ROOT_PATH, MODULES_DIR, module_name))
_LOG.info(f'The {module_name} module was successfully uninstalled')
return CommandResponse(
message=f'\'{module_name}\' successfully uninstalled')