comparison sat_frontends/bridge/dbus_bridge.py @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents frontends/src/bridge/dbus_bridge.py@27539029a662
children 973d4551ffae
comparison
equal deleted inserted replaced
2561:bd30dc3ffe5a 2562:26edcf3a30eb
1 #!/usr/bin/env python2
2 #-*- coding: utf-8 -*-
3
4 # SAT communication bridge
5 # Copyright (C) 2009-2018 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 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(object):
63
64 def bridgeConnect(self, callback, errback):
65 try:
66 self.sessions_bus = dbus.SessionBus()
67 self.db_object = self.sessions_bus.get_object(const_INT_PREFIX,
68 const_OBJ_PATH)
69 self.db_core_iface = dbus.Interface(self.db_object,
70 dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX)
71 self.db_plugin_iface = dbus.Interface(self.db_object,
72 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX)
73 except dbus.exceptions.DBusException, e:
74 if e._dbus_error_name in ('org.freedesktop.DBus.Error.ServiceUnknown',
75 'org.freedesktop.DBus.Error.Spawn.ExecFailed'):
76 errback(BridgeExceptionNoService())
77 elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
78 log.error(_(u"D-Bus is not launched, please see README to see instructions on how to launch it"))
79 errback(BridgeInitError)
80 else:
81 errback(e)
82 callback()
83 #props = self.db_core_iface.getProperties()
84
85 def register_signal(self, functionName, handler, iface="core"):
86 if iface == "core":
87 self.db_core_iface.connect_to_signal(functionName, handler)
88 elif iface == "plugin":
89 self.db_plugin_iface.connect_to_signal(functionName, handler)
90 else:
91 log.error(_('Unknown interface'))
92
93 def __getattribute__(self, name):
94 """ usual __getattribute__ if the method exists, else try to find a plugin method """
95 try:
96 return object.__getattribute__(self, name)
97 except AttributeError:
98 # The attribute is not found, we try the plugin proxy to find the requested method
99
100 def getPluginMethod(*args, **kwargs):
101 # We first check if we have an async call. We detect this in two ways:
102 # - if we have the 'callback' and 'errback' keyword arguments
103 # - or if the last two arguments are callable
104
105 async = False
106 args = list(args)
107
108 if kwargs:
109 if 'callback' in kwargs:
110 async = True
111 _callback = kwargs.pop('callback')
112 _errback = kwargs.pop('errback', lambda failure: log.error(unicode(failure)))
113 try:
114 args.append(kwargs.pop('profile'))
115 except KeyError:
116 try:
117 args.append(kwargs.pop('profile_key'))
118 except KeyError:
119 pass
120 # at this point, kwargs should be empty
121 if kwargs:
122 log.warnings(u"unexpected keyword arguments, they will be ignored: {}".format(kwargs))
123 elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]):
124 async = True
125 _errback = args.pop()
126 _callback = args.pop()
127
128 method = getattr(self.db_plugin_iface, name)
129
130 if async:
131 kwargs['timeout'] = const_TIMEOUT
132 kwargs['reply_handler'] = _callback
133 kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
134
135 return method(*args, **kwargs)
136
137 return getPluginMethod
138
139 def actionsGet(self, profile_key="@DEFAULT@", callback=None, errback=None):
140 if callback is None:
141 error_handler = None
142 else:
143 if errback is None:
144 errback = log.error
145 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
146 kwargs={}
147 if callback is not None:
148 kwargs['timeout'] = const_TIMEOUT
149 kwargs['reply_handler'] = callback
150 kwargs['error_handler'] = error_handler
151 return self.db_core_iface.actionsGet(profile_key, **kwargs)
152
153 def addContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None):
154 if callback is None:
155 error_handler = None
156 else:
157 if errback is None:
158 errback = log.error
159 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
160 kwargs={}
161 if callback is not None:
162 kwargs['timeout'] = const_TIMEOUT
163 kwargs['reply_handler'] = callback
164 kwargs['error_handler'] = error_handler
165 return self.db_core_iface.addContact(entity_jid, profile_key, **kwargs)
166
167 def asyncDeleteProfile(self, profile, callback=None, errback=None):
168 if callback is None:
169 error_handler = None
170 else:
171 if errback is None:
172 errback = log.error
173 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
174 return self.db_core_iface.asyncDeleteProfile(profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
175
176 def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
177 if callback is None:
178 error_handler = None
179 else:
180 if errback is None:
181 errback = log.error
182 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
183 return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
184
185 def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
186 if callback is None:
187 error_handler = None
188 else:
189 if errback is None:
190 errback = log.error
191 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
192 return self.db_core_iface.asyncGetParamsValuesFromCategory(category, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
193
194 def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None):
195 if callback is None:
196 error_handler = None
197 else:
198 if errback is None:
199 errback = log.error
200 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
201 return self.db_core_iface.connect(profile_key, password, options, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
202
203 def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None):
204 if callback is None:
205 error_handler = None
206 else:
207 if errback is None:
208 errback = log.error
209 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
210 return self.db_core_iface.delContact(entity_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
211
212 def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
213 if callback is None:
214 error_handler = None
215 else:
216 if errback is None:
217 errback = log.error
218 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
219 return self.db_core_iface.discoFindByFeatures(namespaces, identities, bare_jid, service, roster, own_jid, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
220
221 def discoInfos(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
222 if callback is None:
223 error_handler = None
224 else:
225 if errback is None:
226 errback = log.error
227 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
228 return self.db_core_iface.discoInfos(entity_jid, node, use_cache, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
229
230 def discoItems(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None):
231 if callback is None:
232 error_handler = None
233 else:
234 if errback is None:
235 errback = log.error
236 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
237 return self.db_core_iface.discoItems(entity_jid, node, use_cache, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
238
239 def disconnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
240 if callback is None:
241 error_handler = None
242 else:
243 if errback is None:
244 errback = log.error
245 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
246 return self.db_core_iface.disconnect(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
247
248 def getConfig(self, section, name, callback=None, errback=None):
249 if callback is None:
250 error_handler = None
251 else:
252 if errback is None:
253 errback = log.error
254 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
255 kwargs={}
256 if callback is not None:
257 kwargs['timeout'] = const_TIMEOUT
258 kwargs['reply_handler'] = callback
259 kwargs['error_handler'] = error_handler
260 return unicode(self.db_core_iface.getConfig(section, name, **kwargs))
261
262 def getContacts(self, profile_key="@DEFAULT@", callback=None, errback=None):
263 if callback is None:
264 error_handler = None
265 else:
266 if errback is None:
267 errback = log.error
268 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
269 return self.db_core_iface.getContacts(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
270
271 def getContactsFromGroup(self, group, profile_key="@DEFAULT@", callback=None, errback=None):
272 if callback is None:
273 error_handler = None
274 else:
275 if errback is None:
276 errback = log.error
277 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
278 kwargs={}
279 if callback is not None:
280 kwargs['timeout'] = const_TIMEOUT
281 kwargs['reply_handler'] = callback
282 kwargs['error_handler'] = error_handler
283 return self.db_core_iface.getContactsFromGroup(group, profile_key, **kwargs)
284
285 def getEntitiesData(self, jids, keys, profile, callback=None, errback=None):
286 if callback is None:
287 error_handler = None
288 else:
289 if errback is None:
290 errback = log.error
291 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
292 kwargs={}
293 if callback is not None:
294 kwargs['timeout'] = const_TIMEOUT
295 kwargs['reply_handler'] = callback
296 kwargs['error_handler'] = error_handler
297 return self.db_core_iface.getEntitiesData(jids, keys, profile, **kwargs)
298
299 def getEntityData(self, jid, keys, profile, callback=None, errback=None):
300 if callback is None:
301 error_handler = None
302 else:
303 if errback is None:
304 errback = log.error
305 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
306 kwargs={}
307 if callback is not None:
308 kwargs['timeout'] = const_TIMEOUT
309 kwargs['reply_handler'] = callback
310 kwargs['error_handler'] = error_handler
311 return self.db_core_iface.getEntityData(jid, keys, profile, **kwargs)
312
313 def getFeatures(self, profile_key, callback=None, errback=None):
314 if callback is None:
315 error_handler = None
316 else:
317 if errback is None:
318 errback = log.error
319 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
320 return self.db_core_iface.getFeatures(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
321
322 def getMainResource(self, contact_jid, profile_key="@DEFAULT@", callback=None, errback=None):
323 if callback is None:
324 error_handler = None
325 else:
326 if errback is None:
327 errback = log.error
328 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
329 kwargs={}
330 if callback is not None:
331 kwargs['timeout'] = const_TIMEOUT
332 kwargs['reply_handler'] = callback
333 kwargs['error_handler'] = error_handler
334 return unicode(self.db_core_iface.getMainResource(contact_jid, profile_key, **kwargs))
335
336 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None):
337 if callback is None:
338 error_handler = None
339 else:
340 if errback is None:
341 errback = log.error
342 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
343 kwargs={}
344 if callback is not None:
345 kwargs['timeout'] = const_TIMEOUT
346 kwargs['reply_handler'] = callback
347 kwargs['error_handler'] = error_handler
348 return unicode(self.db_core_iface.getParamA(name, category, attribute, profile_key, **kwargs))
349
350 def getParamsCategories(self, callback=None, errback=None):
351 if callback is None:
352 error_handler = None
353 else:
354 if errback is None:
355 errback = log.error
356 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
357 kwargs={}
358 if callback is not None:
359 kwargs['timeout'] = const_TIMEOUT
360 kwargs['reply_handler'] = callback
361 kwargs['error_handler'] = error_handler
362 return self.db_core_iface.getParamsCategories(**kwargs)
363
364 def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
365 if callback is None:
366 error_handler = None
367 else:
368 if errback is None:
369 errback = log.error
370 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
371 return unicode(self.db_core_iface.getParamsUI(security_limit, app, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler))
372
373 def getPresenceStatuses(self, profile_key="@DEFAULT@", callback=None, errback=None):
374 if callback is None:
375 error_handler = None
376 else:
377 if errback is None:
378 errback = log.error
379 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
380 kwargs={}
381 if callback is not None:
382 kwargs['timeout'] = const_TIMEOUT
383 kwargs['reply_handler'] = callback
384 kwargs['error_handler'] = error_handler
385 return self.db_core_iface.getPresenceStatuses(profile_key, **kwargs)
386
387 def getReady(self, callback=None, errback=None):
388 if callback is None:
389 error_handler = None
390 else:
391 if errback is None:
392 errback = log.error
393 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
394 return self.db_core_iface.getReady(timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
395
396 def getVersion(self, callback=None, errback=None):
397 if callback is None:
398 error_handler = None
399 else:
400 if errback is None:
401 errback = log.error
402 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
403 kwargs={}
404 if callback is not None:
405 kwargs['timeout'] = const_TIMEOUT
406 kwargs['reply_handler'] = callback
407 kwargs['error_handler'] = error_handler
408 return unicode(self.db_core_iface.getVersion(**kwargs))
409
410 def getWaitingSub(self, profile_key="@DEFAULT@", callback=None, errback=None):
411 if callback is None:
412 error_handler = None
413 else:
414 if errback is None:
415 errback = log.error
416 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
417 kwargs={}
418 if callback is not None:
419 kwargs['timeout'] = const_TIMEOUT
420 kwargs['reply_handler'] = callback
421 kwargs['error_handler'] = error_handler
422 return self.db_core_iface.getWaitingSub(profile_key, **kwargs)
423
424 def historyGet(self, from_jid, to_jid, limit, between=True, filters='', profile="@NONE@", callback=None, errback=None):
425 if callback is None:
426 error_handler = None
427 else:
428 if errback is None:
429 errback = log.error
430 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
431 return self.db_core_iface.historyGet(from_jid, to_jid, limit, between, filters, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
432
433 def isConnected(self, profile_key="@DEFAULT@", callback=None, errback=None):
434 if callback is None:
435 error_handler = None
436 else:
437 if errback is None:
438 errback = log.error
439 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
440 kwargs={}
441 if callback is not None:
442 kwargs['timeout'] = const_TIMEOUT
443 kwargs['reply_handler'] = callback
444 kwargs['error_handler'] = error_handler
445 return self.db_core_iface.isConnected(profile_key, **kwargs)
446
447 def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None):
448 if callback is None:
449 error_handler = None
450 else:
451 if errback is None:
452 errback = log.error
453 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
454 return self.db_core_iface.launchAction(callback_id, data, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
455
456 def loadParamsTemplate(self, filename, callback=None, errback=None):
457 if callback is None:
458 error_handler = None
459 else:
460 if errback is None:
461 errback = log.error
462 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
463 kwargs={}
464 if callback is not None:
465 kwargs['timeout'] = const_TIMEOUT
466 kwargs['reply_handler'] = callback
467 kwargs['error_handler'] = error_handler
468 return self.db_core_iface.loadParamsTemplate(filename, **kwargs)
469
470 def menuHelpGet(self, menu_id, language, callback=None, errback=None):
471 if callback is None:
472 error_handler = None
473 else:
474 if errback is None:
475 errback = log.error
476 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
477 kwargs={}
478 if callback is not None:
479 kwargs['timeout'] = const_TIMEOUT
480 kwargs['reply_handler'] = callback
481 kwargs['error_handler'] = error_handler
482 return unicode(self.db_core_iface.menuHelpGet(menu_id, language, **kwargs))
483
484 def menuLaunch(self, menu_type, path, data, security_limit, profile_key, callback=None, errback=None):
485 if callback is None:
486 error_handler = None
487 else:
488 if errback is None:
489 errback = log.error
490 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
491 return self.db_core_iface.menuLaunch(menu_type, path, data, security_limit, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
492
493 def menusGet(self, language, security_limit, callback=None, errback=None):
494 if callback is None:
495 error_handler = None
496 else:
497 if errback is None:
498 errback = log.error
499 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
500 kwargs={}
501 if callback is not None:
502 kwargs['timeout'] = const_TIMEOUT
503 kwargs['reply_handler'] = callback
504 kwargs['error_handler'] = error_handler
505 return self.db_core_iface.menusGet(language, security_limit, **kwargs)
506
507 def messageSend(self, to_jid, message, subject={}, mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None):
508 if callback is None:
509 error_handler = None
510 else:
511 if errback is None:
512 errback = log.error
513 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
514 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)
515
516 def namespacesGet(self, callback=None, errback=None):
517 if callback is None:
518 error_handler = None
519 else:
520 if errback is None:
521 errback = log.error
522 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
523 kwargs={}
524 if callback is not None:
525 kwargs['timeout'] = const_TIMEOUT
526 kwargs['reply_handler'] = callback
527 kwargs['error_handler'] = error_handler
528 return self.db_core_iface.namespacesGet(**kwargs)
529
530 def paramsRegisterApp(self, xml, security_limit=-1, app='', callback=None, errback=None):
531 if callback is None:
532 error_handler = None
533 else:
534 if errback is None:
535 errback = log.error
536 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
537 kwargs={}
538 if callback is not None:
539 kwargs['timeout'] = const_TIMEOUT
540 kwargs['reply_handler'] = callback
541 kwargs['error_handler'] = error_handler
542 return self.db_core_iface.paramsRegisterApp(xml, security_limit, app, **kwargs)
543
544 def profileCreate(self, profile, password='', component='', callback=None, errback=None):
545 if callback is None:
546 error_handler = None
547 else:
548 if errback is None:
549 errback = log.error
550 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
551 return self.db_core_iface.profileCreate(profile, password, component, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
552
553 def profileIsSessionStarted(self, profile_key="@DEFAULT@", callback=None, errback=None):
554 if callback is None:
555 error_handler = None
556 else:
557 if errback is None:
558 errback = log.error
559 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
560 kwargs={}
561 if callback is not None:
562 kwargs['timeout'] = const_TIMEOUT
563 kwargs['reply_handler'] = callback
564 kwargs['error_handler'] = error_handler
565 return self.db_core_iface.profileIsSessionStarted(profile_key, **kwargs)
566
567 def profileNameGet(self, profile_key="@DEFAULT@", callback=None, errback=None):
568 if callback is None:
569 error_handler = None
570 else:
571 if errback is None:
572 errback = log.error
573 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
574 kwargs={}
575 if callback is not None:
576 kwargs['timeout'] = const_TIMEOUT
577 kwargs['reply_handler'] = callback
578 kwargs['error_handler'] = error_handler
579 return unicode(self.db_core_iface.profileNameGet(profile_key, **kwargs))
580
581 def profileSetDefault(self, profile, callback=None, errback=None):
582 if callback is None:
583 error_handler = None
584 else:
585 if errback is None:
586 errback = log.error
587 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
588 kwargs={}
589 if callback is not None:
590 kwargs['timeout'] = const_TIMEOUT
591 kwargs['reply_handler'] = callback
592 kwargs['error_handler'] = error_handler
593 return self.db_core_iface.profileSetDefault(profile, **kwargs)
594
595 def profileStartSession(self, password='', profile_key="@DEFAULT@", callback=None, errback=None):
596 if callback is None:
597 error_handler = None
598 else:
599 if errback is None:
600 errback = log.error
601 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
602 return self.db_core_iface.profileStartSession(password, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
603
604 def profilesListGet(self, clients=True, components=False, callback=None, errback=None):
605 if callback is None:
606 error_handler = None
607 else:
608 if errback is None:
609 errback = log.error
610 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
611 kwargs={}
612 if callback is not None:
613 kwargs['timeout'] = const_TIMEOUT
614 kwargs['reply_handler'] = callback
615 kwargs['error_handler'] = error_handler
616 return self.db_core_iface.profilesListGet(clients, components, **kwargs)
617
618 def progressGet(self, id, profile, callback=None, errback=None):
619 if callback is None:
620 error_handler = None
621 else:
622 if errback is None:
623 errback = log.error
624 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
625 kwargs={}
626 if callback is not None:
627 kwargs['timeout'] = const_TIMEOUT
628 kwargs['reply_handler'] = callback
629 kwargs['error_handler'] = error_handler
630 return self.db_core_iface.progressGet(id, profile, **kwargs)
631
632 def progressGetAll(self, profile, callback=None, errback=None):
633 if callback is None:
634 error_handler = None
635 else:
636 if errback is None:
637 errback = log.error
638 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
639 kwargs={}
640 if callback is not None:
641 kwargs['timeout'] = const_TIMEOUT
642 kwargs['reply_handler'] = callback
643 kwargs['error_handler'] = error_handler
644 return self.db_core_iface.progressGetAll(profile, **kwargs)
645
646 def progressGetAllMetadata(self, profile, callback=None, errback=None):
647 if callback is None:
648 error_handler = None
649 else:
650 if errback is None:
651 errback = log.error
652 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
653 kwargs={}
654 if callback is not None:
655 kwargs['timeout'] = const_TIMEOUT
656 kwargs['reply_handler'] = callback
657 kwargs['error_handler'] = error_handler
658 return self.db_core_iface.progressGetAllMetadata(profile, **kwargs)
659
660 def saveParamsTemplate(self, filename, callback=None, errback=None):
661 if callback is None:
662 error_handler = None
663 else:
664 if errback is None:
665 errback = log.error
666 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
667 kwargs={}
668 if callback is not None:
669 kwargs['timeout'] = const_TIMEOUT
670 kwargs['reply_handler'] = callback
671 kwargs['error_handler'] = error_handler
672 return self.db_core_iface.saveParamsTemplate(filename, **kwargs)
673
674 def sessionInfosGet(self, profile_key, callback=None, errback=None):
675 if callback is None:
676 error_handler = None
677 else:
678 if errback is None:
679 errback = log.error
680 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
681 return self.db_core_iface.sessionInfosGet(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
682
683 def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
684 if callback is None:
685 error_handler = None
686 else:
687 if errback is None:
688 errback = log.error
689 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
690 kwargs={}
691 if callback is not None:
692 kwargs['timeout'] = const_TIMEOUT
693 kwargs['reply_handler'] = callback
694 kwargs['error_handler'] = error_handler
695 return self.db_core_iface.setParam(name, value, category, security_limit, profile_key, **kwargs)
696
697 def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@", callback=None, errback=None):
698 if callback is None:
699 error_handler = None
700 else:
701 if errback is None:
702 errback = log.error
703 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
704 kwargs={}
705 if callback is not None:
706 kwargs['timeout'] = const_TIMEOUT
707 kwargs['reply_handler'] = callback
708 kwargs['error_handler'] = error_handler
709 return self.db_core_iface.setPresence(to_jid, show, statuses, profile_key, **kwargs)
710
711 def subscription(self, sub_type, entity, profile_key="@DEFAULT@", callback=None, errback=None):
712 if callback is None:
713 error_handler = None
714 else:
715 if errback is None:
716 errback = log.error
717 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
718 kwargs={}
719 if callback is not None:
720 kwargs['timeout'] = const_TIMEOUT
721 kwargs['reply_handler'] = callback
722 kwargs['error_handler'] = error_handler
723 return self.db_core_iface.subscription(sub_type, entity, profile_key, **kwargs)
724
725 def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@", callback=None, errback=None):
726 if callback is None:
727 error_handler = None
728 else:
729 if errback is None:
730 errback = log.error
731 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
732 return self.db_core_iface.updateContact(entity_jid, name, groups, profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)