comparison src/bridge/bridge_constructor/dbus_frontend_template.py @ 1062:95758ef3faa8

bridge: async failures are more detailed (full class name + error message)
author souliane <souliane@mailoo.org>
date Sat, 07 Jun 2014 15:20:39 +0200
parents 301b342c697a
children d123d61976c8
comparison
equal deleted inserted replaced
1061:3700165d68dc 1062:95758ef3faa8
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from bridge_frontend import BridgeFrontend 21 from bridge_frontend import BridgeFrontend, BridgeException
22 import dbus 22 import dbus
23 from sat.core.log import getLogger 23 from sat.core.log import getLogger
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError 25 from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError
26 26
30 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix 30 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix
31 const_ERROR_PREFIX = const_INT_PREFIX + ".error" 31 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
32 const_OBJ_PATH = '/org/goffi/SAT/bridge' 32 const_OBJ_PATH = '/org/goffi/SAT/bridge'
33 const_CORE_SUFFIX = ".core" 33 const_CORE_SUFFIX = ".core"
34 const_PLUGIN_SUFFIX = ".plugin" 34 const_PLUGIN_SUFFIX = ".plugin"
35
36
37 def dbus_to_bridge_exception(dbus_e):
38 """Convert a DBusException to a BridgeException.
39
40 @param dbus_e (DBusException)
41 @return: BridgeException
42 """
43 name = dbus_e.get_dbus_name()[len(const_ERROR_PREFIX) + 1:]
44 return BridgeException(name, dbus_e.get_dbus_message())
35 45
36 46
37 class DBusBridgeFrontend(BridgeFrontend): 47 class DBusBridgeFrontend(BridgeFrontend):
38 def __init__(self): 48 def __init__(self):
39 try: 49 try:
89 99
90 method = getattr(self.db_plugin_iface, name) 100 method = getattr(self.db_plugin_iface, name)
91 101
92 if async: 102 if async:
93 kwargs['reply_handler'] = _callback 103 kwargs['reply_handler'] = _callback
94 kwargs['error_handler'] = lambda err: _errback(err._dbus_error_name[len(const_ERROR_PREFIX) + 1:]) 104 kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
95 105
96 return method(*args, **kwargs) 106 return method(*args, **kwargs)
97 107
98 return getPluginMethod 108 return getPluginMethod
99 ##METHODS_PART## 109 ##METHODS_PART##