Mercurial > libervia-backend
changeset 1587:698d6755d62a
core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 14 Nov 2015 19:18:10 +0100 |
parents | 42285d993e68 |
children | 823a385235ef |
files | frontends/src/bridge/DBus.py src/bridge/DBus.py src/bridge/bridge_constructor/bridge_template.ini src/core/sat_main.py src/memory/memory.py src/memory/params.py |
diffstat | 6 files changed, 74 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py Sat Nov 14 19:18:07 2015 +0100 +++ b/frontends/src/bridge/DBus.py Sat Nov 14 19:18:10 2015 +0100 @@ -173,6 +173,15 @@ error_handler = lambda err:errback(dbus_to_bridge_exception(err)) return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)) + def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): + if callback is None: + error_handler = None + else: + if errback is None: + errback = log.error + error_handler = lambda err:errback(dbus_to_bridge_exception(err)) + return self.db_core_iface.asyncGetParamsValuesFromCategory(category, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) + def confirmationAnswer(self, id, accepted, data, profile, callback=None, errback=None): if callback is None: error_handler = None
--- a/src/bridge/DBus.py Sat Nov 14 19:18:07 2015 +0100 +++ b/src/bridge/DBus.py Sat Nov 14 19:18:10 2015 +0100 @@ -243,6 +243,12 @@ return self._callback("asyncGetParamA", unicode(name), unicode(category), unicode(attribute), security_limit, unicode(profile_key), callback=callback, errback=errback) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, + in_signature='sis', out_signature='a{ss}', + async_callbacks=('callback', 'errback')) + def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): + return self._callback("asyncGetParamsValuesFromCategory", unicode(category), security_limit, unicode(profile_key), callback=callback, errback=errback) + + @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, in_signature='sba{ss}s', out_signature='', async_callbacks=None) def confirmationAnswer(self, id, accepted, data, profile):
--- a/src/bridge/bridge_constructor/bridge_template.ini Sat Nov 14 19:18:07 2015 +0100 +++ b/src/bridge/bridge_constructor/bridge_template.ini Sat Nov 14 19:18:10 2015 +0100 @@ -479,6 +479,19 @@ doc_param_3=%(doc_security_limit)s doc_param_4=%(doc_profile_key)s +[asyncGetParamsValuesFromCategory] +async= +type=method +category=code +sig_in=sis +sig_out=a{ss} +param_1_default=-1 +param_2_default="@DEFAULT@" +doc=Get "attribute" for all params of a category +doc_param_0=category: as for [setParam] +doc_param_1=%(doc_security_limit)s +doc_param_2=%(doc_profile_key)s + [getParamsUI] async= type=method
--- a/src/core/sat_main.py Sat Nov 14 19:18:07 2015 +0100 +++ b/src/core/sat_main.py Sat Nov 14 19:18:10 2015 +0100 @@ -88,6 +88,7 @@ self.bridge.register("setParam", self.setParam) self.bridge.register("getParamA", self.memory.getStringParamA) self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA) + self.bridge.register("asyncGetParamsValuesFromCategory", self.memory.asyncGetParamsValuesFromCategory) self.bridge.register("getParamsUI", self.memory.getParamsUI) self.bridge.register("getParamsCategories", self.memory.getParamsCategories) self.bridge.register("paramsRegisterApp", self.memory.paramsRegisterApp)
--- a/src/memory/memory.py Sat Nov 14 19:18:07 2015 +0100 +++ b/src/memory/memory.py Sat Nov 14 19:18:10 2015 +0100 @@ -858,6 +858,9 @@ def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): return self.params.asyncGetParamA(name, category, attr, security_limit, profile_key) + def asyncGetParamsValuesFromCategory(self, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): + return self.params.asyncGetParamsValuesFromCategory(category, security_limit, profile_key) + def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): return self.params.asyncGetStringParamA(name, category, attr, security_limit, profile_key)
--- a/src/memory/params.py Sat Nov 14 19:18:07 2015 +0100 +++ b/src/memory/params.py Sat Nov 14 19:18:10 2015 +0100 @@ -533,6 +533,48 @@ d = self.storage.getIndParam(category, name, profile) return d.addCallback(lambda value: self._asyncGetAttr(node[1], attr, value, profile)) + def asyncGetParamsValuesFromCategory(self, category, security_limit, profile_key): + """Get all parameters "attribute" for a category + + @param category(unicode): the desired category + @param security_limit(int): NO_SECURITY_LIMIT (-1) to return all the params. + Otherwise sole the params which have a security level defined *and* + lower or equal to the specified value are returned. + @param profile_key: %(doc_profile_key)s + @return (dict): key: param name, value: param value (converted to string if needed) + """ + #TODO: manage category of general type (without existant profile) + profile = self.getProfileName(profile_key) + if not profile: + log.error(_("Asking params for inexistant profile")) + return "" + + def setValue(value, ret, name): + ret[name] = value + + def returnCategoryXml(prof_xml): + ret = {} + names_d_list = [] + for category_node in prof_xml.getElementsByTagName("category"): + if category_node.getAttribute("name") == category: + for param_node in category_node.getElementsByTagName("param"): + name = param_node.getAttribute('name') + if not name: + log.warning(u"ignoring attribute without name: {}".format(param_node.toxml())) + continue + d = self.asyncGetStringParamA(name, category, security_limit=security_limit, profile_key=profile) + d.addCallback(setValue, ret, name) + names_d_list.append(d) + break + + prof_xml.unlink() + dlist = defer.gatherResults(names_d_list) + dlist.addCallback(lambda dummy: ret) + return ret + + d = self._constructProfileXml(security_limit, '', profile) + return d.addCallback(returnCategoryXml) + def _getParam(self, category, name, type_=C.INDIVIDUAL, cache=None, profile=C.PROF_KEY_NONE): """Return the param, or None if it doesn't exist