comparison libervia/server/pages.py @ 1145:29eb15062416

pages: set __name__ for imported pages
author Goffi <goffi@goffi.org>
date Fri, 25 Jan 2019 08:41:43 +0100
parents 2af117bfe6cc
children 76d75423ef53
comparison
equal deleted inserted replaced
1144:2af117bfe6cc 1145:29eb15062416
26 from sat.core.i18n import _ 26 from sat.core.i18n import _
27 from sat.core import exceptions 27 from sat.core import exceptions
28 from sat.tools.common import date_utils 28 from sat.tools.common import date_utils
29 from sat.core.log import getLogger 29 from sat.core.log import getLogger
30 30
31 log = getLogger(__name__)
32 from libervia.server.constants import Const as C 31 from libervia.server.constants import Const as C
33 from libervia.server import session_iface 32 from libervia.server import session_iface
34 from libervia.server.utils import quote, SubPage 33 from libervia.server.utils import quote, SubPage
35 34
36 from collections import namedtuple 35 from collections import namedtuple
37 import uuid 36 import uuid
38 import os.path 37 import os.path
39 import urllib 38 import urllib
40 import time 39 import time
41 import hashlib 40 import hashlib
41
42 log = getLogger(__name__)
42 43
43 WebsocketMeta = namedtuple("WebsocketMeta", ("url", "token", "debug")) 44 WebsocketMeta = namedtuple("WebsocketMeta", ("url", "token", "debug"))
44 45
45 46
46 class CacheBase(object): 47 class CacheBase(object):
278 for d in os.listdir(root_dir): 279 for d in os.listdir(root_dir):
279 dir_path = os.path.join(root_dir, d) 280 dir_path = os.path.join(root_dir, d)
280 if not os.path.isdir(dir_path): 281 if not os.path.isdir(dir_path):
281 continue 282 continue
282 if _extra_pages and d in _parent.children: 283 if _extra_pages and d in _parent.children:
283 log.debug(_(u"[{host_name}] {path} is already present, ignoring it").format( 284 log.debug(_(u"[{host_name}] {path} is already present, ignoring it")
284 host_name=vhost_root.host_name, path=u'/'.join(_path+[d]))) 285 .format(host_name=vhost_root.host_name, path=u'/'.join(_path+[d])))
285 continue 286 continue
286 meta_path = os.path.join(dir_path, C.PAGES_META_FILE) 287 meta_path = os.path.join(dir_path, C.PAGES_META_FILE)
287 if os.path.isfile(meta_path): 288 if os.path.isfile(meta_path):
288 page_data = {} 289 page_data = {"__name__": u".".join([u"page"] + _path + [d])}
289 new_path = _path + [d] 290 new_path = _path + [d]
290 # we don't want to force the presence of __init__.py 291 # we don't want to force the presence of __init__.py
291 # so we use execfile instead of import. 292 # so we use execfile instead of import.
292 # TODO: when moved to Python 3, __init__.py is not mandatory anymore 293 # TODO: when moved to Python 3, __init__.py is not mandatory anymore
293 # so we can switch to import 294 # so we can switch to import
1106 if self.vhost_root.site_name: 1107 if self.vhost_root.site_name:
1107 template_data[u'site'] = self.vhost_root.site_name 1108 template_data[u'site'] = self.vhost_root.site_name
1108 1109
1109 return self.host.renderer.render( 1110 return self.host.renderer.render(
1110 self.template, 1111 self.template,
1111 media_path="/" + C.MEDIA_DIR, 1112 media_path=u"/" + C.MEDIA_DIR,
1112 cache_path=session_data.cache_dir, 1113 cache_path=session_data.cache_dir,
1113 main_menu=self.main_menu, 1114 main_menu=self.main_menu,
1114 **template_data) 1115 **template_data)
1115 1116
1116 def _renderEb(self, failure_, request): 1117 def _renderEb(self, failure_, request):