| 548 | def _call_buddy(self, meth, handle, cb, args, tries, timeout=1): |
| 549 | """Workaround for http://bugs.sugarlabs.org/ticket/2964""" |
| 550 | |
| 551 | if CONNECTION_INTERFACE_BUDDY_INFO not in self._connection: |
| 552 | return |
| 553 | |
| 554 | def error_handler(error): |
| 555 | if tries <= 1: |
| 556 | raise RuntimeError('No luck with %s: %s' % (meth, error)) |
| 557 | logging.debug('Try to call %r in %d seconds', meth, timeout) |
| 558 | gobject.timeout_add_seconds(timeout, self._call_buddy, |
| 559 | meth, handle, cb, args, tries - 1, timeout * 2) |
| 560 | |
| 561 | connection = self._connection[CONNECTION_INTERFACE_BUDDY_INFO] |
| 562 | connection_meth = eval('connection.%s' % meth) |
| 563 | connection_meth(handle, reply_handler=partial(cb, *args), |
| 564 | error_handler=error_handler, byte_arrays=True, |
| 565 | timeout=_QUERY_DBUS_TIMEOUT) |
| 566 | |
574 | | connection = \ |
575 | | self._connection[CONNECTION_INTERFACE_BUDDY_INFO] |
576 | | |
577 | | connection.GetProperties( |
578 | | handle, |
579 | | reply_handler=partial(self.__got_buddy_info_cb, handle, |
580 | | nick), |
581 | | error_handler=partial(self.__error_handler_cb, |
582 | | 'BuddyInfo.GetProperties'), |
583 | | byte_arrays=True, |
584 | | timeout=_QUERY_DBUS_TIMEOUT) |
585 | | |
586 | | connection.GetActivities( |
587 | | handle, |
588 | | reply_handler=partial(self.__got_activities_cb, |
589 | | handle), |
590 | | error_handler=partial(self.__error_handler_cb, |
591 | | 'BuddyInfo.GetActivities'), |
592 | | timeout=_QUERY_DBUS_TIMEOUT) |
593 | | |
594 | | connection.GetCurrentActivity( |
595 | | handle, |
596 | | reply_handler=partial(self.__get_current_activity_cb, |
597 | | handle), |
598 | | error_handler=partial(self.__error_handler_cb, |
599 | | 'BuddyInfo.GetCurrentActivity'), |
600 | | timeout=_QUERY_DBUS_TIMEOUT) |
| 593 | # Without GetProperties, newly appeared buddy |
| 594 | # won't be shown, so try 5 times |
| 595 | self._call_buddy('GetProperties', handle, |
| 596 | self.__got_buddy_info_cb, [handle, nick], 5) |
| 597 | # The rest of data might be not set via pep on the server |
| 598 | self._call_buddy('GetActivities', handle, |
| 599 | self.__got_activities_cb, [handle], 1) |
| 600 | self._call_buddy('GetCurrentActivity', handle, |
| 601 | self.__get_current_activity_cb, [handle], 1) |