From 39e56fed3de9129ff167a632ffbc12340fe665e9 Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Thu, 26 May 2022 09:29:49 +0200 Subject: Switch to inotify, RegexMatchingEventHandler and use set for reloading plugins --- backend/loader.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'backend') diff --git a/backend/loader.py b/backend/loader.py index 9357b4ce..4880790a 100644 --- a/backend/loader.py +++ b/backend/loader.py @@ -8,23 +8,22 @@ from traceback import print_exc from aiohttp import web from aiohttp_jinja2 import template from genericpath import exists -from watchdog.events import FileSystemEventHandler -from watchdog.observers.polling import PollingObserver as Observer +from watchdog.events import RegexMatchingEventHandler +from watchdog.observers.inotify import InotifyObserver as Observer from injector import inject_to_tab from plugin import PluginWrapper -class FileChangeHandler(FileSystemEventHandler): +class FileChangeHandler(RegexMatchingEventHandler): def __init__(self, queue, plugin_path) -> None: - super().__init__() + super().__init__(regexes=[r'^.*?dist\/index\.js$', r'^.*?main\.py$']) self.logger = getLogger("file-watcher") self.plugin_path = plugin_path self.queue = queue def maybe_reload(self, src_path): plugin_dir = Path(path.relpath(src_path, self.plugin_path)).parts[0] - self.logger.info(path.join(self.plugin_path, plugin_dir, "plugin.json")) if exists(path.join(self.plugin_path, plugin_dir, "plugin.json")): self.queue.put_nowait((path.join(self.plugin_path, plugin_dir, "main.py"), plugin_dir, True)) -- cgit v1.2.3