comparison libervia/server/tasks.py @ 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 a1625e68b726
comparison
equal deleted inserted replaced
1146:76d75423ef53 1147:02afab1b15c5
23 from sat.core import exceptions 23 from sat.core import exceptions
24 from sat.core.i18n import _ 24 from sat.core.i18n import _
25 from libervia.server.constants import Const as C 25 from libervia.server.constants import Const as C
26 from collections import OrderedDict 26 from collections import OrderedDict
27 from sat.core.log import getLogger 27 from sat.core.log import getLogger
28 from sat.tools import config
29 from sat.tools.common import async_process 28 from sat.tools.common import async_process
30 29
31 log = getLogger(__name__) 30 log = getLogger(__name__)
32 31
33 32
50 @property 49 @property
51 def site_path(self): 50 def site_path(self):
52 return self.resource.site_path 51 return self.resource.site_path
53 52
54 @property 53 @property
55 def config_section(self):
56 return self.resource.site_name.lower().strip()
57
58 @property
59 def build_path(self): 54 def build_path(self):
60 """path where generated files will be build for this site""" 55 """path where generated files will be build for this site"""
61 if self._build_path is None: 56 if self._build_path is None:
62 self._build_path = self.host.getBuildPath(self.site_name) 57 self._build_path = self.host.getBuildPath(self.site_name)
63 return self._build_path 58 return self._build_path
64 59
65 def getConfig(self, key, default=None, value_type=None): 60 def getConfig(self, key, default=None, value_type=None):
66 """Retrieve configuration associated to this site 61 return self.host.getConfig(self.resource, key=key, default=default,
67 62 value_type=value_type)
68 Section is automatically set to site name
69 @param key(unicode): key to use
70 @param default: value to use if not found (see [config.getConfig])
71 @param value_type(unicode, None): filter to use on value
72 Note that filters are already automatically used when the key finish
73 by a well known suffix ("_path", "_list", "_dict", or "_json")
74 None to use no filter, else can be:
75 - "path": a path is expected, will be normalized and expanded
76
77 """
78 value = config.getConfig(self.host.main_conf, self.config_section, key,
79 default=default)
80 if value_type is not None:
81 if value_type == u'path':
82 v_filter = lambda v: os.path.abspath(os.path.expanduser(v))
83 else:
84 raise ValueError(u"unknown value type {value_type}".format(
85 value_type = value_type))
86 if isinstance(value, list):
87 value = [v_filter(v) for v in value]
88 elif isinstance(value, dict):
89 value = {k:v_filter(v) for k,v in value.items()}
90 elif value is not None:
91 value = v_filter(v)
92 return value
93 63
94 @property 64 @property
95 def site_name(self): 65 def site_name(self):
96 return self.resource.site_name 66 return self.resource.site_name
97 67