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

@ -173,6 +173,15 @@ class DBusBridgeFrontend(BridgeFrontend):
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

View file

@ -242,6 +242,12 @@ class DbusObject(dbus.service.Object):
def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
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)

View file

@ -479,6 +479,19 @@ doc_param_2=attribute: Name of the attribute
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

View file

@ -88,6 +88,7 @@ class SAT(service.Service):
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)

View file

@ -858,6 +858,9 @@ class Memory(object):
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)

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