Export BusException (and code style fixes).
authorBenjamin Braatz <benjamin.braatz@graph-it.com>
Wed, 11 Aug 2021 08:02:28 +0000 (10:02 +0200)
committerBenjamin Braatz <benjamin.braatz@graph-it.com>
Wed, 11 Aug 2021 08:02:28 +0000 (10:02 +0200)
controlpi/__init__.py
controlpi/__main__.py
controlpi/messagebus.py

index cca0c2428e0516e196930f8f7e6388b3ff98e1fe..dfde4e1a28855f02f53d8ef1dff6f1d9cacfda74 100644 (file)
@@ -13,7 +13,8 @@ boilerplate code.
 import asyncio
 import jsonschema  # type: ignore
 
-from controlpi.messagebus import MessageBus, Message, MessageTemplate
+from controlpi.messagebus import (MessageBus, BusException,
+                                  Message, MessageTemplate)
 from controlpi.pluginregistry import PluginRegistry
 from controlpi.baseplugin import BasePlugin, PluginConf, ConfException
 
index 8ef2ea2d4ded59e188f6ed64094cc0c4fd9cc80c..94ff899979b90166b5664674e837d49e172758aa 100644 (file)
@@ -51,7 +51,7 @@ def read_configuration() -> Dict[str, PluginConf]:
     return conf
 
 
-class ConfigChangeHandler(pyinotify.ProcessEvent):
+class ConfigHandler(pyinotify.ProcessEvent):
     def process_IN_MODIFY(self, event):
         if event.pathname == os.path.abspath(sys.argv[1]):
             print(f"Configuration file modified: {event.pathname}")
@@ -64,7 +64,7 @@ async def add_config_change_handler() -> pyinotify.AsyncioNotifier:
     wm = pyinotify.WatchManager()
     loop = asyncio.get_running_loop()
     notifier = pyinotify.AsyncioNotifier(wm, loop,
-                                         default_proc_fun=ConfigChangeHandler())
+                                         default_proc_fun=ConfigHandler())
     wm.add_watch(os.path.dirname(sys.argv[1]), pyinotify.ALL_EVENTS)
     return notifier
 
index dcfe555fce25307befa0cd0c9cfb9263c416570f..54fbf2a9aad9f925cff802f5a6bcefda0edd630b 100644 (file)
@@ -1176,20 +1176,27 @@ class MessageBus:
                         answer = Message('')
                         answer['client'] = client
                         answer['plugin'] = self._plugins[client]
-                        answer['sends'] = self._send_reg.get_templates(client)
-                        answer['receives'] = self._recv_reg.get_templates(client)
+                        answer['sends'] = (self._send_reg
+                                           .get_templates(client))
+                        answer['receives'] = (self._recv_reg
+                                              .get_templates(client))
                         await self._queue.put(answer)
                 elif message['command'] == 'push conf':
                     conf = {}
                     try:
                         with open(sys.argv[1]) as conf_file:
                             conf = json.load(conf_file)
-                    except (IndexError, FileNotFoundError, json.decoder.JSONDecodeError):
+                    except (IndexError, FileNotFoundError,
+                            json.decoder.JSONDecodeError):
                         pass
                     if conf == message['conf']:
-                        await self._queue.put(Message('', {'event': 'conf unchanged'}))
+                        await (self._queue
+                               .put(Message('',
+                                            {'event': 'conf unchanged'})))
                     else:
-                        await self._queue.put(Message('', {'event': 'conf changed'}))
+                        await (self._queue
+                               .put(Message('',
+                                            {'event': 'conf changed'})))
                         with open(sys.argv[1], 'w') as conf_file:
                             json.dump(message['conf'], conf_file)
             for client in self._recv_reg.get(message):