def remove(self, settings): """ Remove the tool: - Remove tool directory into toolbox - Change install status to false. :param Settings settings: Settings from config files :return: Removal status :rtype: bool """ # Delete tool directory if tool was installed inside toolbox directory if self.install_command: if not FileUtils.is_dir(self.tool_dir): logger.warning('Directory "{dir}" does not exist'.format( dir=self.tool_dir)) #return False elif not FileUtils.remove_directory(self.tool_dir): logger.error('Unable to delete directory "{dir}". ' \ 'Check permissions and/or re-run with sudo'.format( dir=self.tool_dir)) return False else: logger.success( 'Tool directory "{dir}" deleted'.format(dir=self.tool_dir)) # Remove virtualenv files if necessary virtualenv_dir = '{}/{}'.format(VIRTUALENVS_DIR, self.name) if FileUtils.is_dir(virtualenv_dir): if FileUtils.remove_directory(virtualenv_dir): logger.success('Virtualenv directory deleted') else: logger.warning('Unable to delete Virtualenv directory') if self.virtualenv.startswith('ruby'): logger.info('Delete RVM environment ({ruby}@{name})...'.format( ruby=self.virtualenv, name=self.name)) cmd = 'source /usr/local/rvm/scripts/rvm; rvm use {ruby} && ' \ 'rvm gemset delete {name} --force'.format( ruby=self.virtualenv, name=self.name) returncode, _ = ProcessLauncher(cmd).start() if returncode == 0: logger.success('RVM environment deleted with success') else: logger.warning('Unable to delete RVM environment') # Make sure "installed" option in config file is set to False if settings.change_installed_status(self.target_service, self.name, install_status=False): logger.success('Tool marked as uninstalled') else: logger.error('An unexpected error occured when trying to mark the tool ' \ 'as uninstalled !') return False self.installed = False return True
def removeTool(self, settings, output): """ Remove tool directory and all files it contains @Args settings: Settings instance output: CLIOutput instance @Returns Boolean indicating status """ if not FileUtils.is_dir(self.tool_dir): output.printInfo('Directory \'{0}\' does not exist'.format( self.tool_dir)) else: if not FileUtils.remove_directory(self.tool_dir): output.printFail( 'Unable to delete directory \'{0}\'. Check permissions and/or re-run with sudo.' .format(self.tool_dir)) return False else: output.printInfo('Directory \'{0}\' deleted'.format( self.tool_dir)) # Make sure "installed" option in config file is set to False if not settings.changeInstalledOption(self.service_name, self.section_name, 'False'): output.printError( 'An unexpected error occured when trying to mark the tool as uninstalled !' ) self.installed = False return True
def removeToolboxForService(self, output, service_name): """ Remove all tools for a given service @Args output: Instance of CLIOutput service_name: Name of the service section (must exist into the toolbox) @Returns Boolean """ if service_name not in self.tools.keys(): return False no_error = True for c in self.settings.general_settings[service_name]['tools_categories']: for t in self.tools[service_name][c]: if t.removeTool(self.settings, output): output.printSuccess('Tool "{0}"" deleted with success'.format(t.name)) else: no_error = False output.printFail('Error during removal of tool "{0}"'.format(t.name)) if no_error: toolbox_service_dir = self.settings.toolbox_dir + os.sep + service_name if FileUtils.remove_directory(toolbox_service_dir): output.printSuccess('Directory "{0}" deleted with success'.format(toolbox_service_dir)) return True else: output.printFail('Directory "{0}" not empty, cannot delete it') return False else: return False
def removeToolboxForService(self, output, service_name): """ Remove all tools for a given service @Args output: Instance of CLIOutput service_name: Name of the service section (must exist into the toolbox) @Returns Boolean """ if service_name not in self.tools.keys(): return False no_error = True for cat in self.tools[service_name].keys(): for tool in self.tools[service_name][cat]: if tool.removeTool(self.settings, output): output.printSuccess('Tool "{0}" deleted with success'.format(tool.name)) elif tool.tooltype != ToolType.USE_MULTI: output.printWarning('Tool "{0}" not deleted'.format(tool.name)) no_error = False if no_error: toolbox_service_dir = self.settings.toolbox_dir + os.sep + service_name if FileUtils.remove_directory(toolbox_service_dir): output.printSuccess('Directory "{0}" deleted with success'.format(toolbox_service_dir)) return True else: output.printWarning('Directory "{0}" not empty, cannot delete it. Try to remove it manually') return False else: return False
def removeTool(self, settings, output): """ Remove the tool: - Remove tool directory into toolbox - Change install status to false @Args settings: Settings instance output: CLIOutput instance @Returns Boolean indicating operation status """ if self.tooltype == ToolType.USE_MULTI: output.printInfo('"{0}" is a reference to the tool "{1}" used for multi services. Not deleted'.format(\ self.name, self.tool_ref_name)) return False if not FileUtils.is_dir(self.tool_dir): output.printInfo('Directory "{0}" does not exist'.format(self.tool_dir)) else: if not FileUtils.remove_directory(self.tool_dir): output.printFail('Unable to delete directory "{0}". Check permissions and/or re-run with sudo'.format(self.tool_dir)) return False else: output.printInfo('Directory "{0}" deleted'.format(self.tool_dir)) # Make sure "installed" option in config file is set to False if not settings.changeInstalledOption(self.service_name, self.name, False): output.printError('An unexpected error occured when trying to mark the tool as uninstalled !') self.installed = False return True
def remove_for_service(self, service): """ Remove the tools for a given service. :param str service: Name of the service targeted by the tools to remove (may be "multi") """ if service not in self.services: return Output.title1( 'Remove tools for service: {service}'.format(service=service)) if not self.tools[service]: logger.info('No tool specific to this service in the toolbox') else: i = 1 status = True for tool in self.tools[service]: if i > 1: print() Output.title2( '[{svc}][{i:02}/{max:02}] Remove {tool_name}:'.format( svc=service, i=i, max=len(self.tools[service]), tool_name=tool.name)) status &= tool.remove(self.settings) i += 1 # Remove the service directory if all tools successfully removed if status: short_svc_path = '{toolbox}/{service}'.format( toolbox=TOOLBOX_DIR, service=service) full_svc_path = FileUtils.absolute_path(short_svc_path) if FileUtils.remove_directory(full_svc_path): logger.success( 'Toolbox service directory "{path}" deleted'.format( path=short_svc_path)) else: logger.warning('Toolbox service directory "{path}" cannot be ' \ 'deleted because it still stores some files'.format( path=short_svc_path))
def remove(self, settings): """ Remove the tool: - Remove tool directory into toolbox - Change install status to false. :param Settings settings: Settings from config files :return: Removal status :rtype: bool """ # Delete tool directory if tool was installed inside toolbox directory if self.install_command: if not FileUtils.is_dir(self.tool_dir): logger.warning('Directory "{dir}" does not exist'.format( dir=self.tool_dir)) return False elif not FileUtils.remove_directory(self.tool_dir): logger.error('Unable to delete directory "{dir}". ' \ 'Check permissions and/or re-run with sudo'.format( dir=self.tool_dir)) return False else: logger.success('Tool directory "{dir}" deleted'.format( dir=self.tool_dir)) # Make sure "installed" option in config file is set to False if settings.change_installed_status(self.target_service, self.name, install_status=False): logger.success('Tool marked as uninstalled') else: logger.error('An unexpected error occured when trying to mark the tool ' \ 'as uninstalled !') return False self.installed = False return True