Mercurial > libervia-backend
comparison frontends/src/bridge/dbus_bridge.py @ 2086:4633cfcbcccb
bridge (D-Bus): bad design fixes:
- renamed outputed module to dbus_bridge (to avoid uppercase and conflict with dbus module)
- class name is now Bridge for both frontend and core (make discovery/import more easy)
- register renamed to register_method in core, and register_signal in frontend
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 03 Oct 2016 21:15:39 +0200 |
parents | frontends/src/bridge/DBus.py@7999d5299ddc |
children | f413bfc24458 |
comparison
equal
deleted
inserted
replaced
2085:da4097de5a95 | 2086:4633cfcbcccb |
---|---|
1 #!/usr/bin/env python2 | |
2 #-*- coding: utf-8 -*- | |
3 | |
4 # SAT communication bridge | |
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
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/>. | |
19 | |
20 from sat.core.i18n import _ | |
21 from bridge_frontend import BridgeFrontend, BridgeException | |
22 import dbus | |
23 from sat.core.log import getLogger | |
24 log = getLogger(__name__) | |
25 from sat.core.exceptions import BridgeExceptionNoService, BridgeInitError | |
26 | |
27 from dbus.mainloop.glib import DBusGMainLoop | |
28 DBusGMainLoop(set_as_default=True) | |
29 | |
30 import ast | |
31 | |
32 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix | |
33 const_ERROR_PREFIX = const_INT_PREFIX + ".error" | |
34 const_OBJ_PATH = '/org/goffi/SAT/bridge' | |
35 const_CORE_SUFFIX = ".core" | |
36 const_PLUGIN_SUFFIX = ".plugin" | |
37 const_TIMEOUT = 120 | |
38 | |
39 | |
40 def dbus_to_bridge_exception(dbus_e): | |
41 """Convert a DBusException to a BridgeException. | |
42 | |
43 @param dbus_e (DBusException) | |
44 @return: BridgeException | |
45 """ | |
46 full_name = dbus_e.get_dbus_name() | |
47 if full_name.startswith(const_ERROR_PREFIX): | |
48 name = dbus_e.get_dbus_name()[len(const_ERROR_PREFIX) + 1:] | |
49 else: | |
50 name = full_name | |
51 # XXX: dbus_e.args doesn't contain the original DBusException args, but we | |
52 # receive its serialized form in dbus_e.args[0]. From that we can rebuild | |
53 # the original arguments list thanks to ast.literal_eval (secure eval). | |
54 message = dbus_e.get_dbus_message() # similar to dbus_e.args[0] | |
55 try: | |
56 message, condition = ast.literal_eval(message) | |
57 except (SyntaxError, ValueError, TypeError): | |
58 condition = '' | |
59 return BridgeException(name, message, condition) | |
60 | |
61 | |
62 class Bridge(BridgeFrontend): | |
63 def __init__(self): | |
64 try: | |
65 self.sessions_bus = dbus.SessionBus() | |
66 self.db_object = self.sessions_bus.get_object(const_INT_PREFIX, | |
67 const_OBJ_PATH) | |
68 self.db_core_iface = dbus.Interface(self.db_object, | |
69 dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX) | |
70 self.db_plugin_iface = dbus.Interface(self.db_object, | |
71 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX) | |
72 except dbus.exceptions.DBusException, e: | |
73 if e._dbus_error_name in ('org.freedesktop.DBus.Error.ServiceUnknown', | |
74 'org.freedesktop.DBus.Error.Spawn.ExecFailed'): | |
75 raise BridgeExceptionNoService | |
76 elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported': | |
77 log.error(_(u"D-Bus is not launched, please see README to see instructions on how to launch it")) | |
78 raise BridgeInitError | |
79 else: | |
80 raise e | |
81 #props = self.db_core_iface.getProperties() | |
82 | |
83 def register_signal(self, functionName, handler, iface="core"): | |
84 if iface == "core": | |
85 self.db_core_iface.connect_to_signal(functionName, handler) | |
86 elif iface == "plugin": | |
87 self.db_plugin_iface.connect_to_signal(functionName, handler) | |
88 else: | |
89 log.error(_('Unknown interface')) | |
90 | |
91 def __getattribute__(self, name): | |
92 """ usual __getattribute__ if the method exists, else try to find a plugin method """ | |
93 try: | |
94 return object.__getattribute__(self, name) | |
95 except AttributeError: | |
96 # The attribute is not found, we try the plugin proxy to find the requested method | |
97 | |
98 def getPluginMethod(*args, **kwargs): | |
99 # We first check if we have an async call. We detect this in two ways: | |
100 # - if we have the 'callback' and 'errback' keyword arguments | |
101 # - or if the last two arguments are callable | |
102 | |
103 async = False | |
104 args = list(args) | |
105 | |
106 if kwargs: | |
107 if 'callback' in kwargs: | |
108 async = True | |
109 _callback = kwargs.pop('callback') | |
110 _errback = kwargs.pop('errback', lambda failure: log.error(unicode(failure))) | |
111 try: | |
112 args.append(kwargs.pop('profile')) | |
113 except KeyError: | |
114 try: | |
115 args.append(kwargs.pop('profile_key')) | |
116 except KeyError: | |
117 pass | |
118 # at this point, kwargs should be empty | |
119 if kwargs: | |
120 log.warnings(u"unexpected keyword arguments, they will be ignored: {}".format(kwargs)) | |
121 elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]): | |
122 async = True | |
123 _errback = args.pop() | |
124 _callback = args.pop() | |
125 | |
126 method = getattr(self.db_plugin_iface, name) | |
127 | |
128 if async: | |
129 kwargs['timeout'] = const_TIMEOUT | |
130 kwargs['reply_handler'] = _callback | |
131 kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err)) | |
132 | |
133 return method(*args, **kwargs) | |
134 | |
135 return getPluginMethod | |
136 | |
137 def actionsGet(self, profile_key="@DEFAULT@", callback=None, errback=None): | |
138 if callback is None: | |
139 error_handler = None | |
140 else: | |
141 if errback is None: | |
142 errback = log.error | |
143 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
144 kwargs={} | |
145 if callback is not None: | |
146 kwargs['timeout'] = const_TIMEOUT | |
147 kwargs['reply_handler'] = callback | |
148 kwargs['error_handler'] = error_handler | |
149 return self.db_core_iface.actionsGet(profile_key, **kwargs) | |
150 | |
151 def addContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None): | |
152 if callback is None: | |
153 error_handler = None | |
154 else: | |
155 if errback is None: | |
156 errback = log.error | |
157 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
158 kwargs={} | |
159 if callback is not None: | |
160 kwargs['timeout'] = const_TIMEOUT | |
161 kwargs['reply_handler'] = callback | |
162 kwargs['error_handler'] = error_handler | |
163 return self.db_core_iface.addContact(entity_jid, profile_key, **kwargs) | |
164 | |
165 def asyncConnect(self, profile_key="@DEFAULT@", password='', callback=None, errback=None): | |
166 if callback is None: | |
167 error_handler = None | |
168 else: | |
169 if errback is None: | |
170 errback = log.error | |
171 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
172 return self.db_core_iface.asyncConnect(profile_key, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
173 | |
174 def asyncCreateProfile(self, profile, password='', callback=None, errback=None): | |
175 if callback is None: | |
176 error_handler = None | |
177 else: | |
178 if errback is None: | |
179 errback = log.error | |
180 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
181 return self.db_core_iface.asyncCreateProfile(profile, password, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
182 | |
183 def asyncDeleteProfile(self, profile, callback=None, errback=None): | |
184 if callback is None: | |
185 error_handler = None | |
186 else: | |
187 if errback is None: | |
188 errback = log.error | |
189 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
190 return self.db_core_iface.asyncDeleteProfile(profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
191 | |
192 def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): | |
193 if callback is None: | |
194 error_handler = None | |
195 else: | |
196 if errback is None: | |
197 errback = log.error | |
198 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
199 return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)) | |
200 | |
201 def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): | |
202 if callback is None: | |
203 error_handler = None | |
204 else: | |
205 if errback is None: | |
206 errback = log.error | |
207 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
208 return self.db_core_iface.asyncGetParamsValuesFromCategory(category, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
209 | |
210 def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None): | |
211 if callback is None: | |
212 error_handler = None | |
213 else: | |
214 if errback is None: | |
215 errback = log.error | |
216 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
217 return self.db_core_iface.delContact(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
218 | |
219 def discoInfos(self, entity_jid, profile_key, callback=None, errback=None): | |
220 if callback is None: | |
221 error_handler = None | |
222 else: | |
223 if errback is None: | |
224 errback = log.error | |
225 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
226 return self.db_core_iface.discoInfos(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
227 | |
228 def discoItems(self, entity_jid, profile_key, callback=None, errback=None): | |
229 if callback is None: | |
230 error_handler = None | |
231 else: | |
232 if errback is None: | |
233 errback = log.error | |
234 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
235 return self.db_core_iface.discoItems(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
236 | |
237 def disconnect(self, profile_key="@DEFAULT@", callback=None, errback=None): | |
238 if callback is None: | |
239 error_handler = None | |
240 else: | |
241 if errback is None: | |
242 errback = log.error | |
243 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
244 kwargs={} | |
245 if callback is not None: | |
246 kwargs['timeout'] = const_TIMEOUT | |
247 kwargs['reply_handler'] = callback | |
248 kwargs['error_handler'] = error_handler | |
249 return self.db_core_iface.disconnect(profile_key, **kwargs) | |
250 | |
251 def getConfig(self, section, name, callback=None, errback=None): | |
252 if callback is None: | |
253 error_handler = None | |
254 else: | |
255 if errback is None: | |
256 errback = log.error | |
257 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
258 kwargs={} | |
259 if callback is not None: | |
260 kwargs['timeout'] = const_TIMEOUT | |
261 kwargs['reply_handler'] = callback | |
262 kwargs['error_handler'] = error_handler | |
263 return unicode(self.db_core_iface.getConfig(section, name, **kwargs)) | |
264 | |
265 def getContacts(self, profile_key="@DEFAULT@", callback=None, errback=None): | |
266 if callback is None: | |
267 error_handler = None | |
268 else: | |
269 if errback is None: | |
270 errback = log.error | |
271 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
272 return self.db_core_iface.getContacts(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
273 | |
274 def getContactsFromGroup(self, group, profile_key="@DEFAULT@", callback=None, errback=None): | |
275 if callback is None: | |
276 error_handler = None | |
277 else: | |
278 if errback is None: | |
279 errback = log.error | |
280 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
281 kwargs={} | |
282 if callback is not None: | |
283 kwargs['timeout'] = const_TIMEOUT | |
284 kwargs['reply_handler'] = callback | |
285 kwargs['error_handler'] = error_handler | |
286 return self.db_core_iface.getContactsFromGroup(group, profile_key, **kwargs) | |
287 | |
288 def getEntitiesData(self, jids, keys, profile, callback=None, errback=None): | |
289 if callback is None: | |
290 error_handler = None | |
291 else: | |
292 if errback is None: | |
293 errback = log.error | |
294 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
295 kwargs={} | |
296 if callback is not None: | |
297 kwargs['timeout'] = const_TIMEOUT | |
298 kwargs['reply_handler'] = callback | |
299 kwargs['error_handler'] = error_handler | |
300 return self.db_core_iface.getEntitiesData(jids, keys, profile, **kwargs) | |
301 | |
302 def getEntityData(self, jid, keys, profile, callback=None, errback=None): | |
303 if callback is None: | |
304 error_handler = None | |
305 else: | |
306 if errback is None: | |
307 errback = log.error | |
308 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
309 kwargs={} | |
310 if callback is not None: | |
311 kwargs['timeout'] = const_TIMEOUT | |
312 kwargs['reply_handler'] = callback | |
313 kwargs['error_handler'] = error_handler | |
314 return self.db_core_iface.getEntityData(jid, keys, profile, **kwargs) | |
315 | |
316 def getFeatures(self, profile_key, callback=None, errback=None): | |
317 if callback is None: | |
318 error_handler = None | |
319 else: | |
320 if errback is None: | |
321 errback = log.error | |
322 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
323 return self.db_core_iface.getFeatures(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
324 | |
325 def getMainResource(self, contact_jid, profile_key="@DEFAULT@", callback=None, errback=None): | |
326 if callback is None: | |
327 error_handler = None | |
328 else: | |
329 if errback is None: | |
330 errback = log.error | |
331 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
332 kwargs={} | |
333 if callback is not None: | |
334 kwargs['timeout'] = const_TIMEOUT | |
335 kwargs['reply_handler'] = callback | |
336 kwargs['error_handler'] = error_handler | |
337 return unicode(self.db_core_iface.getMainResource(contact_jid, profile_key, **kwargs)) | |
338 | |
339 def getMenuHelp(self, menu_id, language, callback=None, errback=None): | |
340 if callback is None: | |
341 error_handler = None | |
342 else: | |
343 if errback is None: | |
344 errback = log.error | |
345 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
346 kwargs={} | |
347 if callback is not None: | |
348 kwargs['timeout'] = const_TIMEOUT | |
349 kwargs['reply_handler'] = callback | |
350 kwargs['error_handler'] = error_handler | |
351 return unicode(self.db_core_iface.getMenuHelp(menu_id, language, **kwargs)) | |
352 | |
353 def getMenus(self, language, security_limit, callback=None, errback=None): | |
354 if callback is None: | |
355 error_handler = None | |
356 else: | |
357 if errback is None: | |
358 errback = log.error | |
359 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
360 kwargs={} | |
361 if callback is not None: | |
362 kwargs['timeout'] = const_TIMEOUT | |
363 kwargs['reply_handler'] = callback | |
364 kwargs['error_handler'] = error_handler | |
365 return self.db_core_iface.getMenus(language, security_limit, **kwargs) | |
366 | |
367 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None): | |
368 if callback is None: | |
369 error_handler = None | |
370 else: | |
371 if errback is None: | |
372 errback = log.error | |
373 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
374 kwargs={} | |
375 if callback is not None: | |
376 kwargs['timeout'] = const_TIMEOUT | |
377 kwargs['reply_handler'] = callback | |
378 kwargs['error_handler'] = error_handler | |
379 return unicode(self.db_core_iface.getParamA(name, category, attribute, profile_key, **kwargs)) | |
380 | |
381 def getParamsCategories(self, callback=None, errback=None): | |
382 if callback is None: | |
383 error_handler = None | |
384 else: | |
385 if errback is None: | |
386 errback = log.error | |
387 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
388 kwargs={} | |
389 if callback is not None: | |
390 kwargs['timeout'] = const_TIMEOUT | |
391 kwargs['reply_handler'] = callback | |
392 kwargs['error_handler'] = error_handler | |
393 return self.db_core_iface.getParamsCategories(**kwargs) | |
394 | |
395 def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): | |
396 if callback is None: | |
397 error_handler = None | |
398 else: | |
399 if errback is None: | |
400 errback = log.error | |
401 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
402 return unicode(self.db_core_iface.getParamsUI(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)) | |
403 | |
404 def getPresenceStatuses(self, profile_key="@DEFAULT@", callback=None, errback=None): | |
405 if callback is None: | |
406 error_handler = None | |
407 else: | |
408 if errback is None: | |
409 errback = log.error | |
410 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
411 kwargs={} | |
412 if callback is not None: | |
413 kwargs['timeout'] = const_TIMEOUT | |
414 kwargs['reply_handler'] = callback | |
415 kwargs['error_handler'] = error_handler | |
416 return self.db_core_iface.getPresenceStatuses(profile_key, **kwargs) | |
417 | |
418 def getProfileName(self, profile_key="@DEFAULT@", callback=None, errback=None): | |
419 if callback is None: | |
420 error_handler = None | |
421 else: | |
422 if errback is None: | |
423 errback = log.error | |
424 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
425 kwargs={} | |
426 if callback is not None: | |
427 kwargs['timeout'] = const_TIMEOUT | |
428 kwargs['reply_handler'] = callback | |
429 kwargs['error_handler'] = error_handler | |
430 return unicode(self.db_core_iface.getProfileName(profile_key, **kwargs)) | |
431 | |
432 def getProfilesList(self, callback=None, errback=None): | |
433 if callback is None: | |
434 error_handler = None | |
435 else: | |
436 if errback is None: | |
437 errback = log.error | |
438 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
439 kwargs={} | |
440 if callback is not None: | |
441 kwargs['timeout'] = const_TIMEOUT | |
442 kwargs['reply_handler'] = callback | |
443 kwargs['error_handler'] = error_handler | |
444 return self.db_core_iface.getProfilesList(**kwargs) | |
445 | |
446 def getReady(self, callback=None, errback=None): | |
447 if callback is None: | |
448 error_handler = None | |
449 else: | |
450 if errback is None: | |
451 errback = log.error | |
452 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
453 return self.db_core_iface.getReady(timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
454 | |
455 def getVersion(self, callback=None, errback=None): | |
456 if callback is None: | |
457 error_handler = None | |
458 else: | |
459 if errback is None: | |
460 errback = log.error | |
461 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
462 kwargs={} | |
463 if callback is not None: | |
464 kwargs['timeout'] = const_TIMEOUT | |
465 kwargs['reply_handler'] = callback | |
466 kwargs['error_handler'] = error_handler | |
467 return unicode(self.db_core_iface.getVersion(**kwargs)) | |
468 | |
469 def getWaitingSub(self, profile_key="@DEFAULT@", callback=None, errback=None): | |
470 if callback is None: | |
471 error_handler = None | |
472 else: | |
473 if errback is None: | |
474 errback = log.error | |
475 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
476 kwargs={} | |
477 if callback is not None: | |
478 kwargs['timeout'] = const_TIMEOUT | |
479 kwargs['reply_handler'] = callback | |
480 kwargs['error_handler'] = error_handler | |
481 return self.db_core_iface.getWaitingSub(profile_key, **kwargs) | |
482 | |
483 def historyGet(self, from_jid, to_jid, limit, between=True, filters='', profile="@NONE@", callback=None, errback=None): | |
484 if callback is None: | |
485 error_handler = None | |
486 else: | |
487 if errback is None: | |
488 errback = log.error | |
489 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
490 return self.db_core_iface.historyGet(from_jid, to_jid, limit, between, filters, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
491 | |
492 def isConnected(self, profile_key="@DEFAULT@", callback=None, errback=None): | |
493 if callback is None: | |
494 error_handler = None | |
495 else: | |
496 if errback is None: | |
497 errback = log.error | |
498 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
499 kwargs={} | |
500 if callback is not None: | |
501 kwargs['timeout'] = const_TIMEOUT | |
502 kwargs['reply_handler'] = callback | |
503 kwargs['error_handler'] = error_handler | |
504 return self.db_core_iface.isConnected(profile_key, **kwargs) | |
505 | |
506 def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None): | |
507 if callback is None: | |
508 error_handler = None | |
509 else: | |
510 if errback is None: | |
511 errback = log.error | |
512 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
513 return self.db_core_iface.launchAction(callback_id, data, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
514 | |
515 def loadParamsTemplate(self, filename, callback=None, errback=None): | |
516 if callback is None: | |
517 error_handler = None | |
518 else: | |
519 if errback is None: | |
520 errback = log.error | |
521 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
522 kwargs={} | |
523 if callback is not None: | |
524 kwargs['timeout'] = const_TIMEOUT | |
525 kwargs['reply_handler'] = callback | |
526 kwargs['error_handler'] = error_handler | |
527 return self.db_core_iface.loadParamsTemplate(filename, **kwargs) | |
528 | |
529 def messageSend(self, to_jid, message, subject={}, mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None): | |
530 if callback is None: | |
531 error_handler = None | |
532 else: | |
533 if errback is None: | |
534 errback = log.error | |
535 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
536 return self.db_core_iface.messageSend(to_jid, message, subject, mess_type, extra, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
537 | |
538 def paramsRegisterApp(self, xml, security_limit=-1, app='', callback=None, errback=None): | |
539 if callback is None: | |
540 error_handler = None | |
541 else: | |
542 if errback is None: | |
543 errback = log.error | |
544 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
545 kwargs={} | |
546 if callback is not None: | |
547 kwargs['timeout'] = const_TIMEOUT | |
548 kwargs['reply_handler'] = callback | |
549 kwargs['error_handler'] = error_handler | |
550 return self.db_core_iface.paramsRegisterApp(xml, security_limit, app, **kwargs) | |
551 | |
552 def profileIsSessionStarted(self, profile_key="@DEFAULT@", callback=None, errback=None): | |
553 if callback is None: | |
554 error_handler = None | |
555 else: | |
556 if errback is None: | |
557 errback = log.error | |
558 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
559 kwargs={} | |
560 if callback is not None: | |
561 kwargs['timeout'] = const_TIMEOUT | |
562 kwargs['reply_handler'] = callback | |
563 kwargs['error_handler'] = error_handler | |
564 return self.db_core_iface.profileIsSessionStarted(profile_key, **kwargs) | |
565 | |
566 def profileSetDefault(self, profile, callback=None, errback=None): | |
567 if callback is None: | |
568 error_handler = None | |
569 else: | |
570 if errback is None: | |
571 errback = log.error | |
572 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
573 kwargs={} | |
574 if callback is not None: | |
575 kwargs['timeout'] = const_TIMEOUT | |
576 kwargs['reply_handler'] = callback | |
577 kwargs['error_handler'] = error_handler | |
578 return self.db_core_iface.profileSetDefault(profile, **kwargs) | |
579 | |
580 def profileStartSession(self, password='', profile_key="@DEFAULT@", callback=None, errback=None): | |
581 if callback is None: | |
582 error_handler = None | |
583 else: | |
584 if errback is None: | |
585 errback = log.error | |
586 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
587 return self.db_core_iface.profileStartSession(password, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) | |
588 | |
589 def progressGet(self, id, profile, callback=None, errback=None): | |
590 if callback is None: | |
591 error_handler = None | |
592 else: | |
593 if errback is None: | |
594 errback = log.error | |
595 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
596 kwargs={} | |
597 if callback is not None: | |
598 kwargs['timeout'] = const_TIMEOUT | |
599 kwargs['reply_handler'] = callback | |
600 kwargs['error_handler'] = error_handler | |
601 return self.db_core_iface.progressGet(id, profile, **kwargs) | |
602 | |
603 def progressGetAll(self, profile, callback=None, errback=None): | |
604 if callback is None: | |
605 error_handler = None | |
606 else: | |
607 if errback is None: | |
608 errback = log.error | |
609 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
610 kwargs={} | |
611 if callback is not None: | |
612 kwargs['timeout'] = const_TIMEOUT | |
613 kwargs['reply_handler'] = callback | |
614 kwargs['error_handler'] = error_handler | |
615 return self.db_core_iface.progressGetAll(profile, **kwargs) | |
616 | |
617 def progressGetAllMetadata(self, profile, callback=None, errback=None): | |
618 if callback is None: | |
619 error_handler = None | |
620 else: | |
621 if errback is None: | |
622 errback = log.error | |
623 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
624 kwargs={} | |
625 if callback is not None: | |
626 kwargs['timeout'] = const_TIMEOUT | |
627 kwargs['reply_handler'] = callback | |
628 kwargs['error_handler'] = error_handler | |
629 return self.db_core_iface.progressGetAllMetadata(profile, **kwargs) | |
630 | |
631 def saveParamsTemplate(self, filename, callback=None, errback=None): | |
632 if callback is None: | |
633 error_handler = None | |
634 else: | |
635 if errback is None: | |
636 errback = log.error | |
637 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
638 kwargs={} | |
639 if callback is not None: | |
640 kwargs['timeout'] = const_TIMEOUT | |
641 kwargs['reply_handler'] = callback | |
642 kwargs['error_handler'] = error_handler | |
643 return self.db_core_iface.saveParamsTemplate(filename, **kwargs) | |
644 | |
645 def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): | |
646 if callback is None: | |
647 error_handler = None | |
648 else: | |
649 if errback is None: | |
650 errback = log.error | |
651 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
652 kwargs={} | |
653 if callback is not None: | |
654 kwargs['timeout'] = const_TIMEOUT | |
655 kwargs['reply_handler'] = callback | |
656 kwargs['error_handler'] = error_handler | |
657 return self.db_core_iface.setParam(name, value, category, security_limit, profile_key, **kwargs) | |
658 | |
659 def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@", callback=None, errback=None): | |
660 if callback is None: | |
661 error_handler = None | |
662 else: | |
663 if errback is None: | |
664 errback = log.error | |
665 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
666 kwargs={} | |
667 if callback is not None: | |
668 kwargs['timeout'] = const_TIMEOUT | |
669 kwargs['reply_handler'] = callback | |
670 kwargs['error_handler'] = error_handler | |
671 return self.db_core_iface.setPresence(to_jid, show, statuses, profile_key, **kwargs) | |
672 | |
673 def subscription(self, sub_type, entity, profile_key="@DEFAULT@", callback=None, errback=None): | |
674 if callback is None: | |
675 error_handler = None | |
676 else: | |
677 if errback is None: | |
678 errback = log.error | |
679 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
680 kwargs={} | |
681 if callback is not None: | |
682 kwargs['timeout'] = const_TIMEOUT | |
683 kwargs['reply_handler'] = callback | |
684 kwargs['error_handler'] = error_handler | |
685 return self.db_core_iface.subscription(sub_type, entity, profile_key, **kwargs) | |
686 | |
687 def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@", callback=None, errback=None): | |
688 if callback is None: | |
689 error_handler = None | |
690 else: | |
691 if errback is None: | |
692 errback = log.error | |
693 error_handler = lambda err:errback(dbus_to_bridge_exception(err)) | |
694 return self.db_core_iface.updateContact(entity_jid, name, groups, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler) |