[engine] Add initial version of event loop engine
Re-add the engine that is responsible for tying together input, output, etc. see #23
This commit is contained in:
parent
e5201187a2
commit
cf1693548b
3 changed files with 56 additions and 0 deletions
18
bumblebee-status
Normal file → Executable file
18
bumblebee-status
Normal file → Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import bumblebee.engine
|
||||||
|
import bumblebee.config
|
||||||
|
|
||||||
|
def main():
|
||||||
|
config = bumblebee.config.Config(sys.argv[1:])
|
||||||
|
engine = bumblebee.engine.Engine(
|
||||||
|
config=config
|
||||||
|
)
|
||||||
|
|
||||||
|
engine.run()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
25
bumblebee/engine.py
Normal file
25
bumblebee/engine.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
"""Core application engine"""
|
||||||
|
|
||||||
|
class Engine(object):
|
||||||
|
"""Engine for driving the application
|
||||||
|
|
||||||
|
This class connects input/output, instantiates all
|
||||||
|
required modules and drives the "event loop"
|
||||||
|
"""
|
||||||
|
def __init__(self, config):
|
||||||
|
self._running = True
|
||||||
|
|
||||||
|
def running(self):
|
||||||
|
"""Check whether the event loop is running"""
|
||||||
|
return self._running
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
"""Stop the event loop"""
|
||||||
|
self._running = False
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""Start the event loop"""
|
||||||
|
while self.running():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
13
tests/test_engine.py
Normal file
13
tests/test_engine.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# pylint: disable=C0103,C0111
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from bumblebee.engine import Engine
|
||||||
|
|
||||||
|
class TestEngine(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.engine = Engine(None)
|
||||||
|
|
||||||
|
def test_stop(self):
|
||||||
|
self.assertTrue(self.engine.running())
|
||||||
|
self.engine.stop()
|
||||||
|
self.assertFalse(self.engine.running())
|
Loading…
Reference in a new issue