[core/config] Add interval (as parameter store)

Add a generic parameter store to the configuration and use it to set the
parameter "interval" (backwards compatibility)
This commit is contained in:
Tobias Witek 2020-01-25 14:24:21 +01:00
parent 8a2ef5ea5d
commit 5a60a23ebd
3 changed files with 32 additions and 4 deletions

View file

@ -1,15 +1,30 @@
import argparse
MODULE_HELP = "Specify a space-separated list of modules to load. The order of the list determines their order in the i3bar (from left to right). Use <module>:<alias> to provide an alias in case you want to load the same module multiple times, but specify different parameters."
import util.store
class Config(object):
MODULE_HELP = "Specify a space-separated list of modules to load. The order of the list determines their order in the i3bar (from left to right). Use <module>:<alias> to provide an alias in case you want to load the same module multiple times, but specify different parameters."
PARAMETER_HELP = "Provide configuration parameters in the form of <module>.<key>=<value>"
class Config(util.store.Store):
def __init__(self, args):
super(Config, self).__init__()
parser = argparse.ArgumentParser(description='bumblebee-status is a modular, theme-able status line generator for the i3 window manager. https://github.com/tobi-wan-kenobi/bumblebee-status/wiki')
parser.add_argument("-m", "--modules", nargs="+", action='append', default=[],
help=MODULE_HELP)
parser.add_argument("-p", "--parameters", nargs="+", action='append', default=[],
help=PARAMETER_HELP)
self._args = parser.parse_args(args)
parameters = [ item for sub in self._args.parameters for item in sub ]
for param in parameters:
key, value = param.split("=", 1)
self.set(key, value)
def modules(self):
return [item for sub in self._args.modules for item in sub]
def interval(self):
return float(self.get("interval", 1))
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4