[core] Pass configuration parameters to modules
User can now use -p <key>=<value> to pass configuration parameters to modules. For this, the module gets a "parameter()" method. Parameter keys are in the format <name>.<key> where <name> is the name of the loaded module. This is either the name of the module itself (e.g. "cpu") or its alias, if the user specified it, for example: bumblebee-status -m cpu -p cpu.warning=90 vs. bumblebee-status -m cpu:test -p test.warning=90 see #23
This commit is contained in:
parent
c8a51b416f
commit
f33711f49f
4 changed files with 52 additions and 5 deletions
|
@ -5,9 +5,11 @@ module parameters, etc.) to all other components
|
|||
"""
|
||||
|
||||
import argparse
|
||||
import bumblebee.store
|
||||
|
||||
MODULE_HELP = ""
|
||||
THEME_HELP = ""
|
||||
PARAMETER_HELP = ""
|
||||
|
||||
def create_parser():
|
||||
"""Create the argument parser"""
|
||||
|
@ -15,18 +17,25 @@ def create_parser():
|
|||
parser.add_argument("-m", "--modules", nargs="+", default=[],
|
||||
help=MODULE_HELP)
|
||||
parser.add_argument("-t", "--theme", default="default", help=THEME_HELP)
|
||||
parser.add_argument("-p", "--parameters", nargs="+", default=[],
|
||||
help=PARAMETER_HELP)
|
||||
return parser
|
||||
|
||||
class Config(object):
|
||||
class Config(bumblebee.store.Store):
|
||||
"""Top-level configuration class
|
||||
|
||||
Parses commandline arguments and provides non-module
|
||||
specific configuration information.
|
||||
"""
|
||||
def __init__(self, args=None):
|
||||
super(Config, self).__init__()
|
||||
parser = create_parser()
|
||||
self._args = parser.parse_args(args if args else [])
|
||||
|
||||
for param in self._args.parameters:
|
||||
key, value = param.split("=")
|
||||
self.set(key, value)
|
||||
|
||||
def modules(self):
|
||||
"""Return a list of all activated modules"""
|
||||
return [{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue