comparison libervia/server/tasks/implicit/task_brython.py @ 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 f2ce8072d89d
children 2796e73ed50c
comparison
equal deleted inserted replaced
1383:81b472bcf0a1 1384:b61509c47cac
57 shutil.copy(data_path / "brython_stdlib.js", self.build_path) 57 shutil.copy(data_path / "brython_stdlib.js", self.build_path)
58 else: 58 else:
59 log.debug("Brython is already installed") 59 log.debug("Brython is already installed")
60 60
61 self.WATCH_DIRS = [] 61 self.WATCH_DIRS = []
62 self.setCommonScripts()
62 63
64 def setCommonScripts(self):
63 for dyn_data in self.resource.browser_modules["brython"]: 65 for dyn_data in self.resource.browser_modules["brython"]:
64 url_hash = dyn_data['url_hash'] 66 url_hash = dyn_data['url_hash']
65 import_url = f"/{C.BUILD_DIR}/{C.BUILD_DIR_DYN}/{url_hash}" 67 import_url = f"/{C.BUILD_DIR}/{C.BUILD_DIR_DYN}/{url_hash}"
66 dyn_data.setdefault('scripts', utils.OrderedSet()).update([ 68 dyn_data.setdefault('scripts', utils.OrderedSet()).update([
67 Script(src=f"/{C.BUILD_DIR}/brython.js"), 69 Script(src=f"/{C.BUILD_DIR}/brython.js"),
89 if p.name == '__pycache__': 91 if p.name == '__pycache__':
90 continue 92 continue
91 shutil.copytree(p, dest / p.name) 93 shutil.copytree(p, dest / p.name)
92 else: 94 else:
93 shutil.copy(p, dest) 95 shutil.copy(p, dest)
96
97 async def onDirEvent(self, host, filepath, flags):
98 self.setCommonScripts()
99 await self.manager.runTaskInstance(self)
94 100
95 def start(self): 101 def start(self):
96 dyn_path = self.build_path / C.BUILD_DIR_DYN 102 dyn_path = self.build_path / C.BUILD_DIR_DYN
97 for dyn_data in self.resource.browser_modules["brython"]: 103 for dyn_data in self.resource.browser_modules["brython"]:
98 url_hash = dyn_data['url_hash'] 104 url_hash = dyn_data['url_hash']
130 136
131 script = Script( 137 script = Script(
132 type='text/python', 138 type='text/python',
133 src=f"/{C.BUILD_DIR}/{C.BUILD_DIR_DYN}/{url_hash}/__init__.py" 139 src=f"/{C.BUILD_DIR}/{C.BUILD_DIR_DYN}/{url_hash}/__init__.py"
134 ) 140 )
135 dyn_data['scripts'].add(script) 141 dyn_data.setdefault('scripts', utils.OrderedSet()).add(script)