From 5a60a23ebd1520275779342756a9457c1633ccff Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 25 Jan 2020 14:24:21 +0100 Subject: [PATCH] [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) --- bumblebee-status | 1 + core/config.py | 19 +++++++++++++++++-- tests/test_config.py | 16 ++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/bumblebee-status b/bumblebee-status index c97d98a..10edfe6 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -17,6 +17,7 @@ def main(): module.update() sys.stdout.write(output.draw(module)) sys.stdout.write(output.end_status_line()) + output.sleep(config.interval()) sys.stdout.write(output.stop()) diff --git a/core/config.py b/core/config.py index 2c227ba..8878ffd 100644 --- a/core/config.py +++ b/core/config.py @@ -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 : 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 : 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 .=" + +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 diff --git a/tests/test_config.py b/tests/test_config.py index e8dee70..fac57ca 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -10,12 +10,24 @@ class config(unittest.TestCase): def tearDown(self): pass - def test_module_parameter(self): + def test_module(self): cfg = core.config.Config([ '-m' ] + self._someModules) self.assertEqual(self._someModules, cfg.modules()) - def test_module_parameter_ordering_maintained(self): + def test_module_ordering_maintained(self): cfg = core.config.Config([ '-m' ] + self._someModules + [ '-m' ] + self._moreModules) self.assertEqual(self._someModules + self._moreModules, cfg.modules()) + def test_default_interval(self): + cfg = core.config.Config([]) + self.assertEqual(1, cfg.interval()) + + def test_interval(self): + cfg = core.config.Config([ '-p', 'interval=4']) + self.assertEqual(4, cfg.interval()) + + def test_float_interval(self): + cfg = core.config.Config([ '-p', 'interval=0.5']) + self.assertEqual(0.5, cfg.interval()) + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4