[core] Re-enable preliminary module loading (stubbed)

Add logic for parsing commandline options, and a preliminary stub for
loading modules.

Note: The idea is that core.module.load() will return a valid, but
empty, module that displays an error, if the module cannot be loaded
This commit is contained in:
Tobias Witek 2020-01-19 15:36:52 +01:00
parent f234f81aa9
commit 8622673114
7 changed files with 68 additions and 6 deletions

View file

@ -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())

15
core/config.py Normal file
View file

@ -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 <module>:<alias> 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

9
core/module.py Normal file
View file

@ -0,0 +1,9 @@
def load(module_name):
pass
class Module(object):
def update(self):
pass
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

0
modules/__init__.py Normal file
View file

14
modules/test.py Normal file
View file

@ -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

21
tests/test_config.py Normal file
View file

@ -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

View file

@ -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