Mercurial > libervia-backend
diff frontends/src/bridge/DBus.py @ 1367:f71a0fc26886
merged branch frontends_multi_profiles
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Mar 2015 10:52:28 +0100 |
parents | bb9c32249778 |
children | 069ad98b360d |
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py Thu Feb 05 11:59:26 2015 +0100 +++ b/frontends/src/bridge/DBus.py Wed Mar 18 10:52:28 2015 +0100 @@ -102,10 +102,10 @@ async = False if kwargs: - if 'callback' in kwargs and 'errback' in kwargs: + if 'callback' in kwargs: async = True _callback = kwargs.pop('callback') - _errback = kwargs.pop('errback') + _errback = kwargs.pop('errback', lambda failure: log.error(unicode(failure))) elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]): async = True args = list(args) @@ -122,138 +122,511 @@ return method(*args, **kwargs) return getPluginMethod - def addContact(self, entity_jid, profile_key="@DEFAULT@"): - return self.db_core_iface.addContact(entity_jid, profile_key) + + def addContact(self, entity_jid, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.addContact(entity_jid, profile_key, **kwargs) def asyncConnect(self, profile_key="@DEFAULT@", password='', callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.asyncConnect(profile_key, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) def asyncCreateProfile(self, profile, password='', callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.asyncCreateProfile(profile, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) def asyncDeleteProfile(self, profile, callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.asyncDeleteProfile(profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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 unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)) - def confirmationAnswer(self, id, accepted, data, profile): - return self.db_core_iface.confirmationAnswer(id, accepted, data, profile) + def confirmationAnswer(self, id, accepted, data, profile, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.confirmationAnswer(id, accepted, data, profile, **kwargs) - def delContact(self, entity_jid, profile_key="@DEFAULT@"): - return self.db_core_iface.delContact(entity_jid, profile_key) + def delContact(self, entity_jid, 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.delContact(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) def discoInfos(self, entity_jid, profile_key, callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.discoInfos(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) def discoItems(self, entity_jid, profile_key, callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.discoItems(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) - def disconnect(self, profile_key="@DEFAULT@"): - return self.db_core_iface.disconnect(profile_key) + def disconnect(self, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.disconnect(profile_key, **kwargs) - def getConfig(self, section, name): - return unicode(self.db_core_iface.getConfig(section, name)) + def getConfig(self, section, name, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return unicode(self.db_core_iface.getConfig(section, name, **kwargs)) + + def getContacts(self, 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.getContacts(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) - def getContacts(self, profile_key="@DEFAULT@"): - return self.db_core_iface.getContacts(profile_key) + def getContactsFromGroup(self, group, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getContactsFromGroup(group, profile_key, **kwargs) - def getContactsFromGroup(self, group, profile_key="@DEFAULT@"): - return self.db_core_iface.getContactsFromGroup(group, profile_key) + def getEntitiesData(self, jids, keys, profile, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getEntitiesData(jids, keys, profile, **kwargs) - def getEntityData(self, jid, keys, profile): - return self.db_core_iface.getEntityData(jid, keys, profile) + def getEntityData(self, jid, keys, profile, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getEntityData(jid, keys, profile, **kwargs) def getHistory(self, from_jid, to_jid, limit, between=True, search='', profile="@NONE@", callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.getHistory(from_jid, to_jid, limit, between, search, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) - def getLastResource(self, contact_jid, profile_key="@DEFAULT@"): - return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key)) + def getMainResource(self, contact_jid, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return unicode(self.db_core_iface.getMainResource(contact_jid, profile_key, **kwargs)) - def getMenuHelp(self, menu_id, language): - return unicode(self.db_core_iface.getMenuHelp(menu_id, language)) + def getMenuHelp(self, menu_id, language, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return unicode(self.db_core_iface.getMenuHelp(menu_id, language, **kwargs)) - def getMenus(self, language, security_limit): - return self.db_core_iface.getMenus(language, security_limit) + def getMenus(self, language, security_limit, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getMenus(language, security_limit, **kwargs) - def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"): - return unicode(self.db_core_iface.getParamA(name, category, attribute, profile_key)) + def getParamA(self, name, category, attribute="value", 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return unicode(self.db_core_iface.getParamA(name, category, attribute, profile_key, **kwargs)) def getParams(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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 unicode(self.db_core_iface.getParams(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)) - def getParamsCategories(self, ): - return self.db_core_iface.getParamsCategories() + def getParamsCategories(self, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getParamsCategories(**kwargs) def getParamsForCategory(self, category, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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 unicode(self.db_core_iface.getParamsForCategory(category, security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)) def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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 unicode(self.db_core_iface.getParamsUI(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)) - def getPresenceStatuses(self, profile_key="@DEFAULT@"): - return self.db_core_iface.getPresenceStatuses(profile_key) + def getPresenceStatuses(self, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getPresenceStatuses(profile_key, **kwargs) - def getProfileName(self, profile_key="@DEFAULT@"): - return unicode(self.db_core_iface.getProfileName(profile_key)) + def getProfileName(self, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return unicode(self.db_core_iface.getProfileName(profile_key, **kwargs)) - def getProfilesList(self, ): - return self.db_core_iface.getProfilesList() + def getProfilesList(self, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getProfilesList(**kwargs) - def getProgress(self, id, profile): - return self.db_core_iface.getProgress(id, profile) + def getProgress(self, id, profile, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getProgress(id, profile, **kwargs) def getReady(self, callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.getReady(timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) - def getVersion(self, ): - return unicode(self.db_core_iface.getVersion()) + def getVersion(self, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return unicode(self.db_core_iface.getVersion(**kwargs)) - def getWaitingConf(self, profile_key): - return self.db_core_iface.getWaitingConf(profile_key) + def getWaitingConf(self, profile_key, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getWaitingConf(profile_key, **kwargs) - def getWaitingSub(self, profile_key="@DEFAULT@"): - return self.db_core_iface.getWaitingSub(profile_key) + def getWaitingSub(self, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.getWaitingSub(profile_key, **kwargs) - def isConnected(self, profile_key="@DEFAULT@"): - return self.db_core_iface.isConnected(profile_key) + def isConnected(self, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.isConnected(profile_key, **kwargs) def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.launchAction(callback_id, data, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) - def loadParamsTemplate(self, filename): - return self.db_core_iface.loadParamsTemplate(filename) + def loadParamsTemplate(self, filename, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.loadParamsTemplate(filename, **kwargs) - def paramsRegisterApp(self, xml, security_limit=-1, app=''): - return self.db_core_iface.paramsRegisterApp(xml, security_limit, app) + def paramsRegisterApp(self, xml, security_limit=-1, app='', 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.paramsRegisterApp(xml, security_limit, app, **kwargs) - def saveParamsTemplate(self, filename): - return self.db_core_iface.saveParamsTemplate(filename) + def saveParamsTemplate(self, filename, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.saveParamsTemplate(filename, **kwargs) def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None): - error_handler = None if callback is None else lambda err:errback(dbus_to_bridge_exception(err)) + 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.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) - def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"): - return self.db_core_iface.setParam(name, value, category, security_limit, profile_key) - - def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"): - return self.db_core_iface.setPresence(to_jid, show, statuses, profile_key) + def setParam(self, name, value, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.setParam(name, value, category, security_limit, profile_key, **kwargs) - def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): - return self.db_core_iface.subscription(sub_type, entity, profile_key) + def setPresence(self, to_jid='', show='', statuses={}, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.setPresence(to_jid, show, statuses, profile_key, **kwargs) - def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@"): - return self.db_core_iface.updateContact(entity_jid, name, groups, profile_key) + def subscription(self, sub_type, entity, 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)) + kwargs={} + if callback is not None: + kwargs['timeout'] = const_TIMEOUT + kwargs['reply_handler'] = callback + kwargs['error_handler'] = error_handler + return self.db_core_iface.subscription(sub_type, entity, profile_key, **kwargs) + + def updateContact(self, entity_jid, name, groups, 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.updateContact(entity_jid, name, groups, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)