changeset 1282:0e4e413eb8db

server: user new OrderedSet to handle scripts: OrderedSet is needed because scripts must not be duplicated and must be generated in right order.
author Goffi <goffi@goffi.org>
date Fri, 19 Jun 2020 16:47:51 +0200
parents 25eacbb1d59e
children 436ef2ad92af
files libervia/server/pages.py libervia/server/server.py libervia/server/tasks/implicit/task_brython.py
diffstat 3 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/pages.py	Fri Jun 19 16:47:50 2020 +0200
+++ b/libervia/server/pages.py	Fri Jun 19 16:47:51 2020 +0200
@@ -129,7 +129,7 @@
         @param host(Libervia): the running instance of Libervia
         @param vhost_root(web_resource.Resource): root resource of the virtual host which
             handle this page.
-        @param root_dir(Path): aboslute file path of the page
+        @param root_dir(Path): absolute file path of the page
         @param url(unicode): relative URL to the page
             this URL may not be valid, as pages may require path arguments
         @param name(unicode, None): if not None, a unique name to identify the page
@@ -1342,12 +1342,12 @@
                 except KeyError:
                     pass
                 else:
-                    template_data.setdefault('scripts', set()).update(scripts)
+                    template_data.setdefault('scripts', utils.OrderedSet()).update(scripts)
                 template_data.update(data.get('template', {}))
         data_common = self.vhost_root.dyn_data_common
         common_scripts = data_common['scripts']
         if common_scripts:
-            template_data.setdefault('scripts', set()).update(common_scripts)
+            template_data.setdefault('scripts', utils.OrderedSet()).update(common_scripts)
             if "template" in data_common:
                 for key, value in data_common["template"].items():
                     if key not in template_data:
--- a/libervia/server/server.py	Fri Jun 19 16:47:50 2020 +0200
+++ b/libervia/server/server.py	Fri Jun 19 16:47:51 2020 +0200
@@ -50,7 +50,7 @@
 from sat.tools.common import regex
 from sat.tools.common import template
 from sat.tools.common import uri as common_uri
-from sat.tools.common.utils import recursive_update
+from sat.tools.common.utils import recursive_update, OrderedSet
 from sat.tools.common import data_format
 from sat.tools.common import tls
 import libervia
@@ -186,7 +186,7 @@
         self.named_pages = {}
         self.browser_modules = {}
         # template dynamic data used in all pages
-        self.dyn_data_common = {"scripts": set()}
+        self.dyn_data_common = {"scripts": OrderedSet()}
         for theme, data in host.renderer.getThemesData(site_name).items():
             # we check themes for browser metadata, and merge them here if found
             self.site_themes.add(theme)
--- a/libervia/server/tasks/implicit/task_brython.py	Fri Jun 19 16:47:50 2020 +0200
+++ b/libervia/server/tasks/implicit/task_brython.py	Fri Jun 19 16:47:51 2020 +0200
@@ -7,6 +7,7 @@
 from sat.core.i18n import _
 from sat.core.log import getLogger
 from sat.core import exceptions
+from sat.tools.common import utils
 from libervia.server.constants import Const as C
 from libervia.server.classes import Script
 from libervia.server.tasks import task
@@ -62,10 +63,10 @@
         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}"
-            dyn_data.setdefault('scripts', set()).update({
+            dyn_data.setdefault('scripts', utils.OrderedSet()).update([
                 Script(src=f"/{C.BUILD_DIR}/brython.js"),
                 Script(src=f"/{C.BUILD_DIR}/brython_stdlib.js"),
-            })
+            ])
             dyn_data.setdefault('template', {})['body_onload'] = self.getBodyOnload(
                 extra_path=[import_url])
             self.WATCH_DIRS.append(dyn_data['path'].resolve())
@@ -108,10 +109,10 @@
 
                 init_file = dyn_data['path'] / '__init__.py'
                 if init_file.is_file():
-                    self.resource.dyn_data_common['scripts'].update({
+                    self.resource.dyn_data_common['scripts'].update([
                         Script(src=f"/{C.BUILD_DIR}/brython.js"),
                         Script(type='text/python', src=init_dest_url)
-                    })
+                    ])
                     self.resource.dyn_data_common.setdefault(
                         "template", {})['body_onload'] = self.getBodyOnload()
             else: