def load_adapter(adapter_name): """ Load adapter which set in bot config. :param adapter_name: name of adapter. May be local package in adapters folder or package from PyPi. :return: """ # Try to import adapter from project directory adapter_module = import_adapter('adapters.{}'.format(adapter_name)) # If it failed, try to import it as PyPi module if adapter_module is None: adapter_module = import_adapter(adapter_name) # If it still fail, just return error if adapter_module is None: logger.critical_message('Problems with importing adapter') return None adapter_config = parse_config(adapter_module) adapter_object = Adapter(adapter_name, adapter_module, adapter_config) return adapter_object
def reload_plugin(self): """ Reload plugin (import it and find hooks again) :return: """ self.module = importlib.reload(self.module) self.config = parse_config(self.module) self.hooks = find_hooks(self.module)
def load_plugin(self, plugin_name): """ Parse config, find hooks and create new Plugin object. :param plugin_name: name for plugin import :return: """ plugin_name = plugin_name.strip() plugin_module = import_plugin(plugin_name) if not plugin_module: logger.error_message("'{}' plugin didn't load".format( plugin_name )) return plugin_config = parse_config(plugin_module) hooks, interval_hooks = find_hooks(plugin_module) plugin = Plugin(plugin_name, plugin_module, plugin_config, hooks, interval_hooks) self.plugins.append(plugin)