Mercurial > libervia-web
changeset 1147:02afab1b15c5
server, pages, tasks: moved getConfig to backend, and added shorcut version in LiberviaPage and TasksManager
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Jan 2019 20:14:09 +0100 |
parents | 76d75423ef53 |
children | 3c7a64adfd42 |
files | libervia/server/pages.py libervia/server/server.py libervia/server/tasks.py |
diffstat | 3 files changed, 36 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/server/pages.py Fri Jan 25 08:58:41 2019 +0100 +++ b/libervia/server/pages.py Sat Jan 26 20:14:09 2019 +0100 @@ -392,6 +392,10 @@ ) request._signals_registered.append(signal) + def getConfig(self, key, default=None, value_type=None): + return self.host.getConfig(self.vhost_root, key=key, default=default, + value_type=value_type) + def getBuildPath(self, session_data): return session_data.cache_dir + self.vhost.site_name
--- a/libervia/server/server.py Fri Jan 25 08:58:41 2019 +0100 +++ b/libervia/server/server.py Sat Jan 26 20:14:09 2019 +0100 @@ -1763,6 +1763,36 @@ self._main_conf = config.parseMainConf() return self._main_conf + def getConfig(self, site_root_res, key, default=None, value_type=None): + """Retrieve configuration associated to a site + + Section is automatically set to site name + @param site_root_res(LiberviaRootResource): resource of the site in use + @param key(unicode): key to use + @param default: value to use if not found (see [config.getConfig]) + @param value_type(unicode, None): filter to use on value + Note that filters are already automatically used when the key finish + by a well known suffix ("_path", "_list", "_dict", or "_json") + None to use no filter, else can be: + - "path": a path is expected, will be normalized and expanded + + """ + section = site_root_res.site_name.lower().strip() + value = config.getConfig(self.main_conf, section, key, default=default) + if value_type is not None: + if value_type == u'path': + v_filter = lambda v: os.path.abspath(os.path.expanduser(v)) + else: + raise ValueError(u"unknown value type {value_type}".format( + value_type = value_type)) + if isinstance(value, list): + value = [v_filter(v) for v in value] + elif isinstance(value, dict): + value = {k:v_filter(v) for k,v in value.items()} + elif value is not None: + value = v_filter(v) + return value + def _namespacesGetCb(self, ns_map): self.ns_map = ns_map
--- a/libervia/server/tasks.py Fri Jan 25 08:58:41 2019 +0100 +++ b/libervia/server/tasks.py Sat Jan 26 20:14:09 2019 +0100 @@ -25,7 +25,6 @@ from libervia.server.constants import Const as C from collections import OrderedDict from sat.core.log import getLogger -from sat.tools import config from sat.tools.common import async_process log = getLogger(__name__) @@ -52,10 +51,6 @@ return self.resource.site_path @property - def config_section(self): - return self.resource.site_name.lower().strip() - - @property def build_path(self): """path where generated files will be build for this site""" if self._build_path is None: @@ -63,33 +58,8 @@ return self._build_path def getConfig(self, key, default=None, value_type=None): - """Retrieve configuration associated to this site - - Section is automatically set to site name - @param key(unicode): key to use - @param default: value to use if not found (see [config.getConfig]) - @param value_type(unicode, None): filter to use on value - Note that filters are already automatically used when the key finish - by a well known suffix ("_path", "_list", "_dict", or "_json") - None to use no filter, else can be: - - "path": a path is expected, will be normalized and expanded - - """ - value = config.getConfig(self.host.main_conf, self.config_section, key, - default=default) - if value_type is not None: - if value_type == u'path': - v_filter = lambda v: os.path.abspath(os.path.expanduser(v)) - else: - raise ValueError(u"unknown value type {value_type}".format( - value_type = value_type)) - if isinstance(value, list): - value = [v_filter(v) for v in value] - elif isinstance(value, dict): - value = {k:v_filter(v) for k,v in value.items()} - elif value is not None: - value = v_filter(v) - return value + return self.host.getConfig(self.resource, key=key, default=default, + value_type=value_type) @property def site_name(self):