[core/engine] Add module loading logic
Allow the engine to load modules from the bumblebee/modules/ directory. see #23
This commit is contained in:
parent
cf1693548b
commit
a2c6214baa
5 changed files with 65 additions and 5 deletions
|
@ -1,5 +1,18 @@
|
|||
"""Core application engine"""
|
||||
|
||||
import importlib
|
||||
|
||||
class Module(object):
|
||||
"""Module instance base class
|
||||
|
||||
Objects of this type represent the modules that
|
||||
the user configures. Concrete module implementations
|
||||
(e.g. CPU utilization, disk usage, etc.) derive from
|
||||
this base class.
|
||||
"""
|
||||
def __init__(self, engine):
|
||||
pass
|
||||
|
||||
class Engine(object):
|
||||
"""Engine for driving the application
|
||||
|
||||
|
@ -8,6 +21,19 @@ class Engine(object):
|
|||
"""
|
||||
def __init__(self, config):
|
||||
self._running = True
|
||||
self._modules = []
|
||||
self.load_modules(config.modules())
|
||||
|
||||
def load_modules(self, modules):
|
||||
"""Load specified modules and return them as list"""
|
||||
for module in modules:
|
||||
self._modules.append(self.load_module(module["module"]))
|
||||
return self._modules
|
||||
|
||||
def load_module(self, module_name):
|
||||
"""Load specified module and return it as object"""
|
||||
module = importlib.import_module("bumblebee.modules.{}".format(module_name))
|
||||
return getattr(module, "Module")(self)
|
||||
|
||||
def running(self):
|
||||
"""Check whether the event loop is running"""
|
||||
|
|
0
bumblebee/modules/__init__.py
Normal file
0
bumblebee/modules/__init__.py
Normal file
11
bumblebee/modules/test.py
Normal file
11
bumblebee/modules/test.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
|
||||
"""Test module"""
|
||||
|
||||
import bumblebee.engine
|
||||
|
||||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine):
|
||||
super(Module, self).__init__(engine)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue