diff libervia/server/pages.py @ 1514:16228994ca3b

server: fix hot reloading of modules in dev mode
author Goffi <goffi@goffi.org>
date Mon, 22 May 2023 11:57:49 +0200
parents 106bae41f5c8
children
line wrap: on
line diff
--- a/libervia/server/pages.py	Mon May 22 11:57:49 2023 +0200
+++ b/libervia/server/pages.py	Mon May 22 11:57:49 2023 +0200
@@ -17,40 +17,43 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from __future__ import annotations
-
-import uuid
-import os.path
-import urllib.request, urllib.parse, urllib.error
-import time
+import copy
+from functools import reduce
 import hashlib
-import copy
 import json
-import traceback
+import os.path
 from pathlib import Path
-from functools import reduce
-from typing import Optional, Union, List
+import time
+import traceback
+from typing import List, Optional, Union
+import urllib.error
+import urllib.parse
+import urllib.request
+import uuid
 
+from twisted.internet import defer
+from twisted.python import failure
+from twisted.python.filepath import FilePath
 from twisted.web import server
 from twisted.web import resource as web_resource
 from twisted.web import util as web_util
-from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
-from twisted.python import failure
 
+from sat.core import exceptions
 from sat.core.i18n import _
-from sat.core import exceptions
-from sat.tools.utils import as_deferred
+from sat.core.log import getLogger
 from sat.tools.common import date_utils
 from sat.tools.common import utils
 from sat.tools.common import data_format
-from sat.core.log import getLogger
+from sat.tools.utils import as_deferred
 from sat_frontends.bridge.bridge_frontend import BridgeException
 
-from .constants import Const as C
 from . import session_iface
-from .utils import quote, SubPage
 from .classes import WebsocketMeta
 from .classes import Script
+from .constants import Const as C
+from .resources import LiberviaRootResource
+from .utils import SubPage, quote
 
 log = getLogger(__name__)
 
@@ -442,15 +445,22 @@
                     cls.create_browser_data(vhost_root, resource, browser_path, new_path)
 
     @classmethod
-    def on_file_change(cls, host, file_path, flags, site_root, site_path):
+    def on_file_change(
+        cls,
+        host,
+        file_path: FilePath,
+        flags: List[str],
+        site_root: LiberviaRootResource,
+        site_path: Path
+    ) -> None:
         """Method triggered by file_watcher when something is changed in files
 
         This method is used in dev mode to reload pages when needed
-        @param file_path(filepath.FilePath): path of the file which triggered the event
-        @param flags[list[unicode]): human readable flags of the event (from
+        @param file_path: path of the file which triggered the event
+        @param flags: human readable flags of the event (from
             internet.inotify)
-        @param site_root(LiberviaRootResource): root of the site
-        @param site_path(unicode): absolute path of the site
+        @param site_root: root of the site
+        @param site_path: absolute path of the site
         """
         if flags == ['create']:
             return