def __scanPlugins(self): """ 扫描插件目录 """ plugin_logger.info("Initialization Plugins Start, loadPlugins path: {0}".format(self.plugin_path)) if os.path.exists(self.plugin_path): for package in os.listdir(self.plugin_path): _plugin_path = os.path.join(self.plugin_path, package) if os.path.isdir(_plugin_path): if os.path.isfile(os.path.join(_plugin_path, "__init__.py")): plugin_logger.info("find plugin package: {0}".format(package)) self.__runPlugins(package) else: plugin_logger.warning("Plugins directory not in here!")
if hasattr(i, "register_bep"): bep = i.register_bep() plugin_logger.info("The plugin {0} wants to register the following blueprint extension points: {1}".format(package, bep)) if isinstance(bep, dict): pluginInfo.update(plugin_bep=bep) plugin_logger.info("Register BEP Success") else: plugin_logger.error("Register BEP Failed, not a dict") #: 加入全局插件中 if hasattr(i, "run") or hasattr(i, "register_tep") or hasattr(i, "register_cep") or hasattr(i, "register_bep"): self.plugins.append(pluginInfo) else: plugin_logger.error("The current class {0} does not have the `run` or `register_tep` or `register_cep` or `register_bep` method".format(i)) else: del plugin plugin_logger.warning("This plugin `{0}` not conform to the standard plugin format".format(package)) @property def get_all_plugins(self): """ 获取所有插件 """ return self.plugins @property def get_enabled_plugins(self): """ 获取所有启用的插件 """ return [p for p in self.get_all_plugins if p["plugin_state"] == "enabled"] @property def get_all_tep(self): """模板扩展点, Template extension point, 更多扩展点自己定义. #No1. 自定义在模板中的扩展点: