Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
1513:ff95501abe74 | 1514:16228994ca3b |
---|---|
15 | 15 |
16 # You should have received a copy of the GNU Affero General Public License | 16 # You should have received a copy of the GNU Affero General Public License |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
19 from __future__ import annotations | 19 from __future__ import annotations |
20 | 20 import copy |
21 from functools import reduce | |
22 import hashlib | |
23 import json | |
24 import os.path | |
25 from pathlib import Path | |
26 import time | |
27 import traceback | |
28 from typing import List, Optional, Union | |
29 import urllib.error | |
30 import urllib.parse | |
31 import urllib.request | |
21 import uuid | 32 import uuid |
22 import os.path | 33 |
23 import urllib.request, urllib.parse, urllib.error | 34 from twisted.internet import defer |
24 import time | 35 from twisted.python import failure |
25 import hashlib | 36 from twisted.python.filepath import FilePath |
26 import copy | |
27 import json | |
28 import traceback | |
29 from pathlib import Path | |
30 from functools import reduce | |
31 from typing import Optional, Union, List | |
32 | |
33 from twisted.web import server | 37 from twisted.web import server |
34 from twisted.web import resource as web_resource | 38 from twisted.web import resource as web_resource |
35 from twisted.web import util as web_util | 39 from twisted.web import util as web_util |
36 from twisted.internet import defer | |
37 from twisted.words.protocols.jabber import jid | 40 from twisted.words.protocols.jabber import jid |
38 from twisted.python import failure | 41 |
39 | 42 from sat.core import exceptions |
40 from sat.core.i18n import _ | 43 from sat.core.i18n import _ |
41 from sat.core import exceptions | 44 from sat.core.log import getLogger |
42 from sat.tools.utils import as_deferred | |
43 from sat.tools.common import date_utils | 45 from sat.tools.common import date_utils |
44 from sat.tools.common import utils | 46 from sat.tools.common import utils |
45 from sat.tools.common import data_format | 47 from sat.tools.common import data_format |
46 from sat.core.log import getLogger | 48 from sat.tools.utils import as_deferred |
47 from sat_frontends.bridge.bridge_frontend import BridgeException | 49 from sat_frontends.bridge.bridge_frontend import BridgeException |
48 | 50 |
49 from .constants import Const as C | |
50 from . import session_iface | 51 from . import session_iface |
51 from .utils import quote, SubPage | |
52 from .classes import WebsocketMeta | 52 from .classes import WebsocketMeta |
53 from .classes import Script | 53 from .classes import Script |
54 from .constants import Const as C | |
55 from .resources import LiberviaRootResource | |
56 from .utils import SubPage, quote | |
54 | 57 |
55 log = getLogger(__name__) | 58 log = getLogger(__name__) |
56 | 59 |
57 | 60 |
58 class CacheBase(object): | 61 class CacheBase(object): |
440 browser_path = dir_path / C.PAGES_BROWSER_DIR | 443 browser_path = dir_path / C.PAGES_BROWSER_DIR |
441 if browser_path.is_dir(): | 444 if browser_path.is_dir(): |
442 cls.create_browser_data(vhost_root, resource, browser_path, new_path) | 445 cls.create_browser_data(vhost_root, resource, browser_path, new_path) |
443 | 446 |
444 @classmethod | 447 @classmethod |
445 def on_file_change(cls, host, file_path, flags, site_root, site_path): | 448 def on_file_change( |
449 cls, | |
450 host, | |
451 file_path: FilePath, | |
452 flags: List[str], | |
453 site_root: LiberviaRootResource, | |
454 site_path: Path | |
455 ) -> None: | |
446 """Method triggered by file_watcher when something is changed in files | 456 """Method triggered by file_watcher when something is changed in files |
447 | 457 |
448 This method is used in dev mode to reload pages when needed | 458 This method is used in dev mode to reload pages when needed |
449 @param file_path(filepath.FilePath): path of the file which triggered the event | 459 @param file_path: path of the file which triggered the event |
450 @param flags[list[unicode]): human readable flags of the event (from | 460 @param flags: human readable flags of the event (from |
451 internet.inotify) | 461 internet.inotify) |
452 @param site_root(LiberviaRootResource): root of the site | 462 @param site_root: root of the site |
453 @param site_path(unicode): absolute path of the site | 463 @param site_path: absolute path of the site |
454 """ | 464 """ |
455 if flags == ['create']: | 465 if flags == ['create']: |
456 return | 466 return |
457 path = Path(file_path.path.decode()) | 467 path = Path(file_path.path.decode()) |
458 base_name = path.name | 468 base_name = path.name |