[core/module] Add config to module

Add access for all modules to the commandline parameters (called
"config" in bumblebee-status)
This commit is contained in:
Tobias Witek 2020-02-03 21:30:06 +01:00
parent 74e74bb78b
commit 3a531c359f
6 changed files with 22 additions and 11 deletions

View file

@ -3,21 +3,25 @@ import logging
log = logging.getLogger(__name__)
def load(module_name):
def load(module_name, config=None):
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)
return getattr(mod, 'Module')()
return getattr(mod, 'Module')(config)
class Module(object):
def __init__(self, widgets):
def __init__(self, config=None, widgets=[]):
self._config = config
self._widgets = widgets if isinstance(widgets, list) else [ widgets ]
def update(self):
pass
def name(self):
return self.__module__.split('.')[-1]
def widgets(self):
return self._widgets