How to use the mqttwarn.util.load_module function in mqttwarn

To help you get started, we’ve selected a few mqttwarn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jpmens / mqttwarn / tests / test_util.py View on Github external
def test_load_module():
    module = load_module('mqttwarn/services/file.py')
    assert 'plugin' in dir(module)
    assert module.plugin.__code__.co_argcount == 2
    assert 'srv' in module.plugin.__code__.co_varnames
    assert 'item' in module.plugin.__code__.co_varnames
github jpmens / mqttwarn / mqttwarn / core.py View on Github external
def load_services(services):
    for service in services:
        service_plugins[service] = {}

        service_config = cf.config('config:' + service)
        if service_config is None:
            logger.error("Service `%s' has no config section" % service)
            sys.exit(1)

        service_plugins[service]['config'] = service_config

        module = cf.g('config:' + service, 'module', service)
        modulefile = resource_filename('mqttwarn.services', module + '.py')

        try:
            service_plugins[service]['module'] = load_module(modulefile)
            logger.info('Successfully loaded service "{}"'.format(service))
        except Exception as ex:
            logger.exception('Unable to load service "{}" from file "{}": {}'.format(service, modulefile, ex))