comparison libervia/server/server.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 49ff1330c9d0
comparison
equal deleted inserted replaced
1146:76d75423ef53 1147:02afab1b15c5
1760 def main_conf(self): 1760 def main_conf(self):
1761 """SafeConfigParser instance opened on configuration file (sat.conf)""" 1761 """SafeConfigParser instance opened on configuration file (sat.conf)"""
1762 if self._main_conf is None: 1762 if self._main_conf is None:
1763 self._main_conf = config.parseMainConf() 1763 self._main_conf = config.parseMainConf()
1764 return self._main_conf 1764 return self._main_conf
1765
1766 def getConfig(self, site_root_res, key, default=None, value_type=None):
1767 """Retrieve configuration associated to a site
1768
1769 Section is automatically set to site name
1770 @param site_root_res(LiberviaRootResource): resource of the site in use
1771 @param key(unicode): key to use
1772 @param default: value to use if not found (see [config.getConfig])
1773 @param value_type(unicode, None): filter to use on value
1774 Note that filters are already automatically used when the key finish
1775 by a well known suffix ("_path", "_list", "_dict", or "_json")
1776 None to use no filter, else can be:
1777 - "path": a path is expected, will be normalized and expanded
1778
1779 """
1780 section = site_root_res.site_name.lower().strip()
1781 value = config.getConfig(self.main_conf, section, key, default=default)
1782 if value_type is not None:
1783 if value_type == u'path':
1784 v_filter = lambda v: os.path.abspath(os.path.expanduser(v))
1785 else:
1786 raise ValueError(u"unknown value type {value_type}".format(
1787 value_type = value_type))
1788 if isinstance(value, list):
1789 value = [v_filter(v) for v in value]
1790 elif isinstance(value, dict):
1791 value = {k:v_filter(v) for k,v in value.items()}
1792 elif value is not None:
1793 value = v_filter(v)
1794 return value
1765 1795
1766 def _namespacesGetCb(self, ns_map): 1796 def _namespacesGetCb(self, ns_map):
1767 self.ns_map = ns_map 1797 self.ns_map = ns_map
1768 1798
1769 def _namespacesGetEb(self, failure_): 1799 def _namespacesGetEb(self, failure_):