Mercurial > libervia-backend
diff src/memory/params.py @ 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 | ab54af2a9ab2 |
line wrap: on
line diff
--- 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