[engine] Allow config parameter fallback to config file
If a configuration parameter is *not* specified with -p on the commandline, look for a INI style configuration file as fallback in ~/.bumblebee-status.conf or ~/.config/bumblebee-status.conf. Section must be "module-parameters", like this: [module-parameters] github.token=<your github token> fixes #138
This commit is contained in:
parent
8941f60572
commit
ab989d8ddf
1 changed files with 20 additions and 1 deletions
|
@ -7,6 +7,11 @@ import importlib
|
||||||
import bumblebee.error
|
import bumblebee.error
|
||||||
import bumblebee.modules
|
import bumblebee.modules
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ConfigParser import SafeConfigParser
|
||||||
|
except ImportError:
|
||||||
|
from configparser import SafeConfigParser
|
||||||
|
|
||||||
def all_modules():
|
def all_modules():
|
||||||
"""Return a list of available modules"""
|
"""Return a list of available modules"""
|
||||||
result = []
|
result = []
|
||||||
|
@ -29,6 +34,14 @@ class Module(object):
|
||||||
self.name = config.get("name", self.__module__.split(".")[-1])
|
self.name = config.get("name", self.__module__.split(".")[-1])
|
||||||
self._config = config
|
self._config = config
|
||||||
self.id = self.name
|
self.id = self.name
|
||||||
|
|
||||||
|
self._configFile = None
|
||||||
|
for cfg in [ os.path.expanduser("~/.bumblebee-status.conf"), os.path.expanduser("~/.config/bumblebee-status.conf") ]:
|
||||||
|
if os.path.exists(cfg):
|
||||||
|
self._configFile = SafeConfigParser()
|
||||||
|
self._configFile.read(cfg)
|
||||||
|
break
|
||||||
|
|
||||||
self._widgets = []
|
self._widgets = []
|
||||||
if widgets:
|
if widgets:
|
||||||
self._widgets = widgets if isinstance(widgets, list) else [widgets]
|
self._widgets = widgets if isinstance(widgets, list) else [widgets]
|
||||||
|
@ -58,7 +71,13 @@ class Module(object):
|
||||||
def parameter(self, name, default=None):
|
def parameter(self, name, default=None):
|
||||||
"""Return the config parameter 'name' for this module"""
|
"""Return the config parameter 'name' for this module"""
|
||||||
name = "{}.{}".format(self.name, name)
|
name = "{}.{}".format(self.name, name)
|
||||||
return self._config["config"].get(name, default)
|
value = self._config["config"].get(name, default)
|
||||||
|
if value == default:
|
||||||
|
try:
|
||||||
|
value = self._configFile.get("module-parameters", name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return value
|
||||||
|
|
||||||
def threshold_state(self, value, warn, crit):
|
def threshold_state(self, value, warn, crit):
|
||||||
if value > float(self.parameter("critical", crit)):
|
if value > float(self.parameter("critical", crit)):
|
||||||
|
|
Loading…
Reference in a new issue