Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1586:42285d993e68 | 1587:698d6755d62a |
---|---|
531 except exceptions.ProfileNotInCacheError: | 531 except exceptions.ProfileNotInCacheError: |
532 #We have to ask data to the storage manager | 532 #We have to ask data to the storage manager |
533 d = self.storage.getIndParam(category, name, profile) | 533 d = self.storage.getIndParam(category, name, profile) |
534 return d.addCallback(lambda value: self._asyncGetAttr(node[1], attr, value, profile)) | 534 return d.addCallback(lambda value: self._asyncGetAttr(node[1], attr, value, profile)) |
535 | 535 |
536 def asyncGetParamsValuesFromCategory(self, category, security_limit, profile_key): | |
537 """Get all parameters "attribute" for a category | |
538 | |
539 @param category(unicode): the desired category | |
540 @param security_limit(int): NO_SECURITY_LIMIT (-1) to return all the params. | |
541 Otherwise sole the params which have a security level defined *and* | |
542 lower or equal to the specified value are returned. | |
543 @param profile_key: %(doc_profile_key)s | |
544 @return (dict): key: param name, value: param value (converted to string if needed) | |
545 """ | |
546 #TODO: manage category of general type (without existant profile) | |
547 profile = self.getProfileName(profile_key) | |
548 if not profile: | |
549 log.error(_("Asking params for inexistant profile")) | |
550 return "" | |
551 | |
552 def setValue(value, ret, name): | |
553 ret[name] = value | |
554 | |
555 def returnCategoryXml(prof_xml): | |
556 ret = {} | |
557 names_d_list = [] | |
558 for category_node in prof_xml.getElementsByTagName("category"): | |
559 if category_node.getAttribute("name") == category: | |
560 for param_node in category_node.getElementsByTagName("param"): | |
561 name = param_node.getAttribute('name') | |
562 if not name: | |
563 log.warning(u"ignoring attribute without name: {}".format(param_node.toxml())) | |
564 continue | |
565 d = self.asyncGetStringParamA(name, category, security_limit=security_limit, profile_key=profile) | |
566 d.addCallback(setValue, ret, name) | |
567 names_d_list.append(d) | |
568 break | |
569 | |
570 prof_xml.unlink() | |
571 dlist = defer.gatherResults(names_d_list) | |
572 dlist.addCallback(lambda dummy: ret) | |
573 return ret | |
574 | |
575 d = self._constructProfileXml(security_limit, '', profile) | |
576 return d.addCallback(returnCategoryXml) | |
577 | |
536 def _getParam(self, category, name, type_=C.INDIVIDUAL, cache=None, profile=C.PROF_KEY_NONE): | 578 def _getParam(self, category, name, type_=C.INDIVIDUAL, cache=None, profile=C.PROF_KEY_NONE): |
537 """Return the param, or None if it doesn't exist | 579 """Return the param, or None if it doesn't exist |
538 | 580 |
539 @param category: param category | 581 @param category: param category |
540 @param name: param name | 582 @param name: param name |