[config] Allow parameter passing via commandline

Allow the user to specify arbitrary configuration parameters from the
commandline and evaluate those in the modules (and elsewhere). Re-enable
the CPU module as a first showcase of this functionality.
This commit is contained in:
Tobias Witek 2016-11-05 12:28:05 +01:00
parent 353c47d76e
commit 18d7e1befb
4 changed files with 29 additions and 12 deletions

View file

@ -47,9 +47,16 @@ class Config(object):
self._args = self._parser.parse_args(args)
for p in self._args.parameters:
key, value = p.split("=")
self.parameter(key, value)
def set(self, name, value):
self._store[name] = value
def parameter(self, name, default=None):
if not name in self._store:
self._store[name] = default
self.set(name, default)
return self._store.get(name, default)
def increase(self, name, limit, default):
@ -76,6 +83,10 @@ class Config(object):
choices = [ "modules", "themes" ],
action=print_usage,
)
parser.add_argument("-p", "--parameters", nargs="+",
help="Provide configuration parameters to individual modules.",
default=[]
)
parser.add_argument("-t", "--theme", help="Specify which theme to use for "
"drawing the modules",
default="default",