2020-01-19 16:06:21 +01:00
|
|
|
import importlib
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
2020-01-19 15:36:52 +01:00
|
|
|
|
2020-02-03 21:30:06 +01:00
|
|
|
def load(module_name, config=None):
|
2020-01-19 16:06:21 +01:00
|
|
|
try:
|
|
|
|
mod = importlib.import_module('modules.{}'.format(module_name))
|
|
|
|
except ImportError as error:
|
|
|
|
log.fatal('failed to import {}: {}'.format(module_name, str(error)))
|
|
|
|
return Error(module_name)
|
2020-02-03 21:30:06 +01:00
|
|
|
return getattr(mod, 'Module')(config)
|
2020-01-19 15:36:52 +01:00
|
|
|
|
|
|
|
class Module(object):
|
2020-02-03 21:30:06 +01:00
|
|
|
def __init__(self, config=None, widgets=[]):
|
|
|
|
self._config = config
|
2020-01-26 14:06:09 +01:00
|
|
|
self._widgets = widgets if isinstance(widgets, list) else [ widgets ]
|
|
|
|
|
2020-01-19 15:36:52 +01:00
|
|
|
def update(self):
|
|
|
|
pass
|
|
|
|
|
2020-02-03 21:30:06 +01:00
|
|
|
def name(self):
|
|
|
|
return self.__module__.split('.')[-1]
|
|
|
|
|
2020-01-26 14:06:09 +01:00
|
|
|
def widgets(self):
|
|
|
|
return self._widgets
|
|
|
|
|
2020-01-19 16:06:21 +01:00
|
|
|
class Error(Module):
|
|
|
|
def __init__(self, loaded_module_name):
|
|
|
|
self._loaded_module_name = loaded_module_name
|
|
|
|
|
2020-01-19 15:36:52 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|