diff --git a/bumblebee-status b/bumblebee-status index c6a4850..c97d98a 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -1,17 +1,20 @@ #!/usr/bin/env python import sys +import core.config import core.output def main(): + config = core.config.Config(sys.argv[1:]) output = core.output.i3() modules = [] -# modules = core.module.modules() + for module in config.modules(): + modules.append(core.module.load(module)) sys.stdout.write(output.start()) while True: sys.stdout.write(output.begin_status_line()) for module in modules: -# module.update() + module.update() sys.stdout.write(output.draw(module)) sys.stdout.write(output.end_status_line()) sys.stdout.write(output.stop()) diff --git a/core/config.py b/core/config.py new file mode 100644 index 0000000..2c227ba --- /dev/null +++ b/core/config.py @@ -0,0 +1,15 @@ +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." + +class Config(object): + def __init__(self, args): + 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) + self._args = parser.parse_args(args) + + def modules(self): + return [item for sub in self._args.modules for item in sub] + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/module.py b/core/module.py new file mode 100644 index 0000000..4307014 --- /dev/null +++ b/core/module.py @@ -0,0 +1,9 @@ + +def load(module_name): + pass + +class Module(object): + def update(self): + pass + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/modules/__init__.py b/modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/test.py b/modules/test.py new file mode 100644 index 0000000..5e92e0e --- /dev/null +++ b/modules/test.py @@ -0,0 +1,14 @@ +# pylint: disable=C0111,R0903 + +"""Test module +""" + +import bumblebee.engine + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text="test") + ) + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..e8dee70 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,21 @@ +import unittest + +import core.config + +class config(unittest.TestCase): + def setUp(self): + self._someModules = [ 'b', 'x', 'a' ] + self._moreModules = [ 'this', 'module', 'here' ] + + def tearDown(self): + pass + + def test_module_parameter(self): + cfg = core.config.Config([ '-m' ] + self._someModules) + self.assertEqual(self._someModules, cfg.modules()) + + def test_module_parameter_ordering_maintained(self): + cfg = core.config.Config([ '-m' ] + self._someModules + [ '-m' ] + self._moreModules) + self.assertEqual(self._someModules + self._moreModules, cfg.modules()) + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/test_output.py b/tests/test_output.py index b073d4c..17526f3 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -12,16 +12,16 @@ class i3(unittest.TestCase): def test_start(self): data = json.loads(self.i3.start()) - self.assertEquals(1, data['version'], 'i3bar protocol version 1 expected') + self.assertEqual(1, data['version'], 'i3bar protocol version 1 expected') self.assertTrue(data['click_events'], 'click events should be enabled') def test_begin_status_line(self): - self.assertEquals('[', self.i3.begin_status_line(), 'each line must be a JSON array') + self.assertEqual('[', self.i3.begin_status_line(), 'each line must be a JSON array') def test_end_status_line(self): - self.assertEquals('],\n', self.i3.end_status_line(), 'each line must terminate properly') + self.assertEqual('],\n', self.i3.end_status_line(), 'each line must terminate properly') def test_stop(self): - self.assertEquals(']\n', self.i3.stop()) + self.assertEqual(']\n', self.i3.stop()) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4