bumblebee-status/bumblebee/module.py
Tobias Witek a9a62a738d [modules] Re-enable nic module + allow widget states
All callback from a widget into a module (e.g. for retrieving the status
or the criticality state) now get a widget passed. This has the purpose
of allowing a module to store state/widget specific data somewhere. This
way, for instance, it is possible to store the interface name as part of
the widget, thus making it possible to show the status of the correct
interface.
2016-11-05 13:42:26 +01:00

51 lines
1.2 KiB
Python

import os
import pkgutil
import importlib
import bumblebee.modules
def modules():
result = []
path = os.path.dirname(bumblebee.modules.__file__)
for mod in [ name for _, name, _ in pkgutil.iter_modules([path])]:
result.append(ModuleDescription(mod))
return result
class ModuleDescription(object):
def __init__(self, name):
self._name = name
self._mod =importlib.import_module("bumblebee.modules.{}".format(name))
def name(self):
return str(self._name)
def description(self):
return getattr(self._mod, "description", self.na)()
def usage(self):
return getattr(self._mod, "usage", self.na)()
def notes(self):
return getattr(self._mod, "notes", self.na)()
def na(self):
return "n/a"
class Module(object):
def __init__(self, output, config):
self._config = config
self._output = output
def critical(self, widget):
return False
def warning(self, widget):
return False
def state(self, widget):
return "default"
def instance(self, widget):
return None
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4