From 7f10bd509337a17359084d3ea0605882f1239744 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Wed, 11 Aug 2021 10:02:28 +0200 Subject: [PATCH] Export BusException (and code style fixes). --- controlpi/__init__.py | 3 ++- controlpi/__main__.py | 4 ++-- controlpi/messagebus.py | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/controlpi/__init__.py b/controlpi/__init__.py index cca0c24..dfde4e1 100644 --- a/controlpi/__init__.py +++ b/controlpi/__init__.py @@ -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 diff --git a/controlpi/__main__.py b/controlpi/__main__.py index 8ef2ea2..94ff899 100644 --- a/controlpi/__main__.py +++ b/controlpi/__main__.py @@ -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 diff --git a/controlpi/messagebus.py b/controlpi/messagebus.py index dcfe555..54fbf2a 100644 --- a/controlpi/messagebus.py +++ b/controlpi/messagebus.py @@ -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): -- 2.34.1