def __collect_and_process_new_plugins( self, filter: Callable[[str], bool]) -> SingleOperationResult: result = SingleOperationResult() for plugin_directory in self.plugin_directories: file_list = file_util.list_file_with_suffix( plugin_directory, constant.PLUGIN_FILE_SUFFIX) for file_path in file_list: if not self.contains_plugin_file(file_path) and filter( file_path): plugin = self.__load_plugin(file_path) if plugin is None: result.fail(file_path) else: result.succeed(plugin) return result
def __collect_and_process_new_plugins( self, filter: Callable[[str], bool]) -> SingleOperationResult: result = SingleOperationResult() for plugin_directory in self.plugin_directories: if os.path.isdir(plugin_directory): for file in os.listdir(plugin_directory): file_path = os.path.join(plugin_directory, file) if plugin_factory.maybe_plugin(file_path): if not self.contains_plugin_file(file_path) and filter( file_path): plugin = self.__load_plugin(file_path) if plugin is None: result.fail(file_path) else: result.succeed(plugin) else: self.logger.warning( 'Plugin directory "{}" not found'.format(plugin_directory)) return result
def __collect_and_process_new_plugins( self, filter: Callable[[str], bool], *, possible_paths: Optional[List[str]] = None ) -> SingleOperationResult: """ :param filter: A str predicate function for testing if the plugin file path is acceptable :param possible_paths: Optional. If you have already done self.__collect_possible_plugin_file_paths() before, you can pass the previous result as the argument to reuse that, so less time cost """ if possible_paths is None: possible_paths = self.__collect_possible_plugin_file_paths() result = SingleOperationResult() for file_path in possible_paths: if not self.contains_plugin_file(file_path) and filter(file_path): plugin = self.__load_plugin(file_path) if plugin is None: result.fail(file_path) else: result.succeed(plugin) return result