core, bridge (params): added asyncGetParamsValuesFromCategory (yes that's a long name!) method to retrive params names and values for a given category

This commit is contained in:
Goffi 2015-11-14 19:18:10 +01:00
commit ce4e717ea8
6 changed files with 74 additions and 0 deletions

View file

@ -533,6 +533,48 @@ class Params(object):
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