Take into account strict and exclude loading extra listeners

This commit is contained in:
Ben 2019-06-03 19:12:49 +01:00
parent cc4a394e77
commit 95af513ac1

View File

@ -110,17 +110,25 @@ class _XMLListener(_Listener):
class _ListenerManager(_AbstractManager): class _ListenerManager(_AbstractManager):
def __init__(self, server):
self.strict_load = None
self.exclude_load = None
super().__init__(server)
def setup(self, module, strict_load=None, exclude_load=None): def setup(self, module, strict_load=None, exclude_load=None):
self.strict_load, self.exclude_load = strict_load, exclude_load
for handler_module in self.server.get_package_modules(module): for handler_module in self.server.get_package_modules(module):
if not (strict_load and handler_module not in strict_load or exclude_load
and handler_module in exclude_load):
module = sys.modules[handler_module] if handler_module in sys.modules.keys() \ module = sys.modules[handler_module] if handler_module in sys.modules.keys() \
else importlib.import_module(handler_module) else importlib.import_module(handler_module)
self.load(module) self.load(module)
self.logger.info('Handler modules loaded') self.logger.debug('Loaded {} listeners'.format(len(self)))
def load(self, module): def load(self, module):
module_name = module.__module__ if isinstance(module, plugins.IPlugin) else module.__name__
if not (self.strict_load and module_name not in self.strict_load or
self.exclude_load and module_name in self.exclude_load):
listener_objects = inspect.getmembers(module, self.is_listener) listener_objects = inspect.getmembers(module, self.is_listener)
for listener_name, listener_object in listener_objects: for listener_name, listener_object in listener_objects:
if isinstance(module, plugins.IPlugin): if isinstance(module, plugins.IPlugin):