[core] Add simple module loading
Add a way to load modules located in modules/*
This commit is contained in:
parent
8622673114
commit
bd12a51bfb
3 changed files with 41 additions and 7 deletions
|
@ -1,9 +1,22 @@
|
|||
import importlib
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def load(module_name):
|
||||
pass
|
||||
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')()
|
||||
|
||||
class Module(object):
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
class Error(Module):
|
||||
def __init__(self, loaded_module_name):
|
||||
self._loaded_module_name = loaded_module_name
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue