core (memory/params): added extra argument to filter out params notably in getParamsUI:

In some case, it may be desirable for a frontend to not expose some parameters to user
(e.g. it is the case on Android with the `autoconnect_backend` parameter). An new `extra`
parameter has been added to a couple of parameters method for that: it can contain the
`ignore` key with a list of [category, name] of parameters to skip.
This commit is contained in:
Goffi 2020-01-25 21:08:40 +01:00
commit 87659cf0f0
3 changed files with 244 additions and 232 deletions

View file

@ -184,14 +184,14 @@ class Bridge:
error_handler = lambda err:errback(dbus_to_bridge_exception(err))
return str(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):
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, app="", extra="", 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)
return self.db_core_iface.asyncGetParamsValuesFromCategory(category, security_limit, app, extra, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None):
if callback is None:
@ -400,14 +400,14 @@ class Bridge:
kwargs['error_handler'] = error_handler
return self.db_core_iface.getParamsCategories(**kwargs)
def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
def getParamsUI(self, security_limit=-1, app='', extra='', 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 str(self.db_core_iface.getParamsUI(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
return str(self.db_core_iface.getParamsUI(security_limit, app, extra, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
def getPresenceStatuses(self, profile_key="@DEFAULT@", callback=None, errback=None):
if callback is None:
@ -908,12 +908,12 @@ class AIOBridge(Bridge):
self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
return fut
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@"):
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, app="", extra="", profile_key="@DEFAULT@"):
loop = asyncio.get_running_loop()
fut = loop.create_future()
reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
self.db_core_iface.asyncGetParamsValuesFromCategory(category, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
self.db_core_iface.asyncGetParamsValuesFromCategory(category, security_limit, app, extra, profile_key, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
return fut
def connect(self, profile_key="@DEFAULT@", password='', options={}):
@ -1060,12 +1060,12 @@ class AIOBridge(Bridge):
self.db_core_iface.getParamsCategories(timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
return fut
def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@"):
def getParamsUI(self, security_limit=-1, app='', extra='', profile_key="@DEFAULT@"):
loop = asyncio.get_running_loop()
fut = loop.create_future()
reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
self.db_core_iface.getParamsUI(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
self.db_core_iface.getParamsUI(security_limit, app, extra, profile_key, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
return fut
def getPresenceStatuses(self, profile_key="@DEFAULT@"):

View file

@ -175,8 +175,8 @@ class Bridge(object):
errback = self._generic_errback
d.addErrback(errback)
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
d = self.root.callRemote("asyncGetParamsValuesFromCategory", category, security_limit, profile_key)
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, app="", extra="", profile_key="@DEFAULT@", callback=None, errback=None):
d = self.root.callRemote("asyncGetParamsValuesFromCategory", category, security_limit, app, extra, profile_key)
if callback is not None:
d.addCallback(callback)
if errback is None:
@ -327,8 +327,8 @@ class Bridge(object):
errback = self._generic_errback
d.addErrback(errback)
def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
d = self.root.callRemote("getParamsUI", security_limit, app, profile_key)
def getParamsUI(self, security_limit=-1, app='', extra='', profile_key="@DEFAULT@", callback=None, errback=None):
d = self.root.callRemote("getParamsUI", security_limit, app, extra, profile_key)
if callback is not None:
d.addCallback(callback)
if errback is None:
@ -664,8 +664,8 @@ class AIOBridge(Bridge):
d.addErrback(self._errback)
return d.asFuture(asyncio.get_event_loop())
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@"):
d = self.root.callRemote("asyncGetParamsValuesFromCategory", category, security_limit, profile_key)
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, app="", extra="", profile_key="@DEFAULT@"):
d = self.root.callRemote("asyncGetParamsValuesFromCategory", category, security_limit, app, extra, profile_key)
d.addErrback(self._errback)
return d.asFuture(asyncio.get_event_loop())
@ -759,8 +759,8 @@ class AIOBridge(Bridge):
d.addErrback(self._errback)
return d.asFuture(asyncio.get_event_loop())
def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@"):
d = self.root.callRemote("getParamsUI", security_limit, app, profile_key)
def getParamsUI(self, security_limit=-1, app='', extra='', profile_key="@DEFAULT@"):
d = self.root.callRemote("getParamsUI", security_limit, app, extra, profile_key)
d.addErrback(self._errback)
return d.asFuture(asyncio.get_event_loop())

View file

@ -47,7 +47,7 @@ class Get(base.CommandBase):
elif self.args.name is None:
try:
values_dict = await self.host.bridge.asyncGetParamsValuesFromCategory(
self.args.category, self.args.security_limit, self.profile)
self.args.category, self.args.security_limit, "", "", self.profile)
except Exception as e:
self.disp(_(f"can't find requested parameters: {e}"), error=True)
self.host.quit(C.EXIT_NOT_FOUND)