[modules] Add module-specific configuration

Big oversight in my previous commits: Widgets need to be able to have
specific configurations (i.e. the path for different instances of the
"disk" module has to be different).

To account for that, it is now possible to assign an "alias" to a module
instance using ":" (for example: -m "disk:home"). This alias is then
used for the configuration parameter resolution automatically, for
example:

-m disk:home -p home.path=/home

As a consequence, parameter names in the module code are now relative to
the module, which means: shorter!
This commit is contained in:
Tobias Witek 2016-11-05 14:26:02 +01:00
parent 9f9b27ad7a
commit 4e648cf009
11 changed files with 62 additions and 40 deletions

View file

@ -12,12 +12,13 @@ def description():
return "Shows available RAM, total amount of RAM and the percentage of available RAM."
class Module(bumblebee.module.Module):
def __init__(self, output, config):
super(Module, self).__init__(output, config)
def __init__(self, output, config, alias):
super(Module, self).__init__(output, config, alias)
self._mem = psutil.virtual_memory()
output.add_callback(module=self.__module__, button=1,
cmd="gnome-system-monitor")
# TODO
# output.add_callback(module=self.__module__, button=1,
# cmd="gnome-system-monitor")
def widgets(self):
self._mem = psutil.virtual_memory()
@ -31,9 +32,9 @@ class Module(bumblebee.module.Module):
)
def warning(self, widget):
return self._mem.percent < self._config.parameter("memory.warning", 20)
return self._mem.percent < self._config.parameter("warning", 20)
def critical(self, widget):
return self._mem.percent < self._config.parameter("memory.critical", 10)
return self._mem.percent < self._config.parameter("critical", 10)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4