changeset 1384:b61509c47cac

tasks (brython): fixed Brython scripts during dev mode reload
author Goffi <goffi@goffi.org>
date Sat, 20 Feb 2021 13:56:08 +0100
parents 81b472bcf0a1
children 4b6f711b09cb
files libervia/server/tasks/implicit/task_brython.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/tasks/implicit/task_brython.py	Sat Feb 20 13:55:00 2021 +0100
+++ b/libervia/server/tasks/implicit/task_brython.py	Sat Feb 20 13:56:08 2021 +0100
@@ -59,7 +59,9 @@
             log.debug("Brython is already installed")
 
         self.WATCH_DIRS = []
+        self.setCommonScripts()
 
+    def setCommonScripts(self):
         for dyn_data in self.resource.browser_modules["brython"]:
             url_hash = dyn_data['url_hash']
             import_url = f"/{C.BUILD_DIR}/{C.BUILD_DIR_DYN}/{url_hash}"
@@ -92,6 +94,10 @@
             else:
                 shutil.copy(p, dest)
 
+    async def onDirEvent(self, host, filepath, flags):
+        self.setCommonScripts()
+        await self.manager.runTaskInstance(self)
+
     def start(self):
         dyn_path = self.build_path / C.BUILD_DIR_DYN
         for dyn_data in self.resource.browser_modules["brython"]:
@@ -132,4 +138,4 @@
                     type='text/python',
                     src=f"/{C.BUILD_DIR}/{C.BUILD_DIR_DYN}/{url_hash}/__init__.py"
                 )
-                dyn_data['scripts'].add(script)
+                dyn_data.setdefault('scripts', utils.OrderedSet()).add(script)