pep8'd sugar3.presence
This commit is contained in:
parent
edbc8f53b3
commit
69a7aa8f68
@ -29,15 +29,15 @@ from dbus import PROPERTIES_IFACE
|
||||
from gi.repository import GObject
|
||||
from telepathy.client import Channel
|
||||
from telepathy.interfaces import CHANNEL, \
|
||||
CHANNEL_INTERFACE_GROUP, \
|
||||
CHANNEL_TYPE_TUBES, \
|
||||
CHANNEL_TYPE_TEXT, \
|
||||
CONNECTION, \
|
||||
PROPERTIES_INTERFACE
|
||||
CHANNEL_INTERFACE_GROUP, \
|
||||
CHANNEL_TYPE_TUBES, \
|
||||
CHANNEL_TYPE_TEXT, \
|
||||
CONNECTION, \
|
||||
PROPERTIES_INTERFACE
|
||||
from telepathy.constants import CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES, \
|
||||
HANDLE_TYPE_ROOM, \
|
||||
HANDLE_TYPE_CONTACT, \
|
||||
PROPERTY_FLAG_WRITE
|
||||
HANDLE_TYPE_ROOM, \
|
||||
HANDLE_TYPE_CONTACT, \
|
||||
PROPERTY_FLAG_WRITE
|
||||
|
||||
from sugar3.presence.buddy import Buddy
|
||||
|
||||
@ -64,13 +64,13 @@ class Activity(GObject.GObject):
|
||||
"""
|
||||
__gsignals__ = {
|
||||
'buddy-joined': (GObject.SignalFlags.RUN_FIRST, None,
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
'buddy-left': (GObject.SignalFlags.RUN_FIRST, None,
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
'new-channel': (GObject.SignalFlags.RUN_FIRST, None,
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
'joined': (GObject.SignalFlags.RUN_FIRST, None,
|
||||
([GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT])),
|
||||
([GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT])),
|
||||
}
|
||||
|
||||
__gproperties__ = {
|
||||
@ -120,22 +120,22 @@ class Activity(GObject.GObject):
|
||||
def _start_tracking_properties(self):
|
||||
bus = dbus.SessionBus()
|
||||
self._get_properties_call = bus.call_async(
|
||||
self.telepathy_conn.requested_bus_name,
|
||||
self.telepathy_conn.object_path,
|
||||
CONN_INTERFACE_ACTIVITY_PROPERTIES,
|
||||
'GetProperties',
|
||||
'u',
|
||||
(self.room_handle,),
|
||||
reply_handler=self.__got_properties_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
utf8_strings=True)
|
||||
self.telepathy_conn.requested_bus_name,
|
||||
self.telepathy_conn.object_path,
|
||||
CONN_INTERFACE_ACTIVITY_PROPERTIES,
|
||||
'GetProperties',
|
||||
'u',
|
||||
(self.room_handle,),
|
||||
reply_handler=self.__got_properties_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
utf8_strings=True)
|
||||
|
||||
# As only one Activity instance is needed per activity process,
|
||||
# we can afford listening to ActivityPropertiesChanged like this.
|
||||
self.telepathy_conn.connect_to_signal(
|
||||
'ActivityPropertiesChanged',
|
||||
self.__activity_properties_changed_cb,
|
||||
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
|
||||
'ActivityPropertiesChanged',
|
||||
self.__activity_properties_changed_cb,
|
||||
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
|
||||
|
||||
def __activity_properties_changed_cb(self, room_handle, properties):
|
||||
_logger.debug('%r: Activity properties changed to %r', self,
|
||||
@ -257,10 +257,12 @@ class Activity(GObject.GObject):
|
||||
if not self._joined:
|
||||
raise RuntimeError('Cannot invite a buddy to an activity that is'
|
||||
'not shared.')
|
||||
self.telepathy_text_chan.AddMembers([buddy.contact_handle], message,
|
||||
dbus_interface=CHANNEL_INTERFACE_GROUP,
|
||||
reply_handler=partial(self.__invite_cb, response_cb),
|
||||
error_handler=partial(self.__invite_cb, response_cb))
|
||||
self.telepathy_text_chan.AddMembers(
|
||||
[buddy.contact_handle], message,
|
||||
dbus_interface=CHANNEL_INTERFACE_GROUP,
|
||||
reply_handler=partial(
|
||||
self.__invite_cb, response_cb),
|
||||
error_handler=partial(self.__invite_cb, response_cb))
|
||||
|
||||
def __invite_cb(self, response_cb, error=None):
|
||||
response_cb(error)
|
||||
@ -305,7 +307,8 @@ class Activity(GObject.GObject):
|
||||
|
||||
def _resolve_handles(self, input_handles, reply_cb):
|
||||
def get_handle_owners_cb(handles):
|
||||
self.telepathy_conn.InspectHandles(HANDLE_TYPE_CONTACT, handles,
|
||||
self.telepathy_conn.InspectHandles(
|
||||
HANDLE_TYPE_CONTACT, handles,
|
||||
reply_handler=reply_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
dbus_interface=CONNECTION)
|
||||
@ -407,7 +410,7 @@ class Activity(GObject.GObject):
|
||||
self.telepathy_tubes_chan = share_command.tubes_channel
|
||||
self._channel_self_handle = share_command.channel_self_handle
|
||||
self._text_channel_group_flags = \
|
||||
share_command.text_channel_group_flags
|
||||
share_command.text_channel_group_flags
|
||||
self._publish_properties()
|
||||
self._start_tracking_properties()
|
||||
self._start_tracking_buddies()
|
||||
@ -430,9 +433,9 @@ class Activity(GObject.GObject):
|
||||
properties['private'] = self._private
|
||||
|
||||
self.telepathy_conn.SetProperties(
|
||||
self.room_handle,
|
||||
properties,
|
||||
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
|
||||
self.room_handle,
|
||||
properties,
|
||||
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
|
||||
|
||||
def __share_error_cb(self, share_activity_error_cb, error):
|
||||
logging.debug('%r: Share failed because: %s', self, error)
|
||||
@ -557,21 +560,26 @@ class _JoinCommand(_BaseCommand):
|
||||
raise RuntimeError('This command has already finished')
|
||||
|
||||
self._connection.Get(CONNECTION, 'SelfHandle',
|
||||
reply_handler=self.__get_self_handle_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
dbus_interface=PROPERTIES_IFACE)
|
||||
reply_handler=self.__get_self_handle_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
dbus_interface=PROPERTIES_IFACE)
|
||||
|
||||
def __get_self_handle_cb(self, handle):
|
||||
self._global_self_handle = handle
|
||||
|
||||
self._connection.RequestChannel(CHANNEL_TYPE_TEXT,
|
||||
HANDLE_TYPE_ROOM, self.room_handle, True,
|
||||
self._connection.RequestChannel(
|
||||
CHANNEL_TYPE_TEXT,
|
||||
HANDLE_TYPE_ROOM,
|
||||
self.room_handle, True,
|
||||
reply_handler=self.__create_text_channel_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
dbus_interface=CONNECTION)
|
||||
|
||||
self._connection.RequestChannel(CHANNEL_TYPE_TUBES,
|
||||
HANDLE_TYPE_ROOM, self.room_handle, True,
|
||||
self._connection.RequestChannel(
|
||||
CHANNEL_TYPE_TUBES,
|
||||
HANDLE_TYPE_ROOM,
|
||||
self.room_handle,
|
||||
True,
|
||||
reply_handler=self.__create_tubes_channel_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
dbus_interface=CONNECTION)
|
||||
@ -600,7 +608,7 @@ class _JoinCommand(_BaseCommand):
|
||||
|
||||
def _tubes_ready(self):
|
||||
if self.text_channel is None or \
|
||||
self.tubes_channel is None:
|
||||
self.tubes_channel is None:
|
||||
return
|
||||
|
||||
_logger.debug('%r: finished setting up tubes', self)
|
||||
@ -633,9 +641,10 @@ class _JoinCommand(_BaseCommand):
|
||||
if self_handle in local_pending:
|
||||
_logger.debug('%r: We are in local pending - entering', self)
|
||||
group.AddMembers([self_handle], '',
|
||||
reply_handler=lambda: None,
|
||||
error_handler=lambda e: self._join_failed_cb(e,
|
||||
'got_all_members AddMembers'))
|
||||
reply_handler=lambda: None,
|
||||
error_handler=lambda e: self._join_failed_cb(
|
||||
e,
|
||||
'got_all_members AddMembers'))
|
||||
|
||||
if members:
|
||||
self.__text_channel_members_changed_cb('', members, (),
|
||||
|
@ -27,8 +27,8 @@ from gi.repository import GObject
|
||||
import dbus
|
||||
from gi.repository import GConf
|
||||
from telepathy.interfaces import CONNECTION, \
|
||||
CONNECTION_INTERFACE_ALIASING, \
|
||||
CONNECTION_INTERFACE_CONTACTS
|
||||
CONNECTION_INTERFACE_ALIASING, \
|
||||
CONNECTION_INTERFACE_CONTACTS
|
||||
from telepathy.constants import HANDLE_TYPE_CONTACT
|
||||
|
||||
from sugar3.presence.connectionmanager import get_connection_manager
|
||||
@ -58,11 +58,11 @@ class BaseBuddy(GObject.GObject):
|
||||
|
||||
__gsignals__ = {
|
||||
'joined-activity': (GObject.SignalFlags.RUN_FIRST, None,
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
'left-activity': (GObject.SignalFlags.RUN_FIRST, None,
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
'property-changed': (GObject.SignalFlags.RUN_FIRST, None,
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
([GObject.TYPE_PYOBJECT])),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
@ -165,27 +165,27 @@ class Buddy(BaseBuddy):
|
||||
self.contact_handle = handles[0]
|
||||
|
||||
self._get_properties_call = bus.call_async(
|
||||
connection_name,
|
||||
connection.object_path,
|
||||
CONN_INTERFACE_BUDDY_INFO,
|
||||
'GetProperties',
|
||||
'u',
|
||||
(self.contact_handle,),
|
||||
reply_handler=self.__got_properties_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
utf8_strings=True,
|
||||
byte_arrays=True)
|
||||
connection_name,
|
||||
connection.object_path,
|
||||
CONN_INTERFACE_BUDDY_INFO,
|
||||
'GetProperties',
|
||||
'u',
|
||||
(self.contact_handle,),
|
||||
reply_handler=self.__got_properties_cb,
|
||||
error_handler=self.__error_handler_cb,
|
||||
utf8_strings=True,
|
||||
byte_arrays=True)
|
||||
|
||||
self._get_attributes_call = bus.call_async(
|
||||
connection_name,
|
||||
connection.object_path,
|
||||
CONNECTION_INTERFACE_CONTACTS,
|
||||
'GetContactAttributes',
|
||||
'auasb',
|
||||
([self.contact_handle], [CONNECTION_INTERFACE_ALIASING],
|
||||
False),
|
||||
reply_handler=self.__got_attributes_cb,
|
||||
error_handler=self.__error_handler_cb)
|
||||
connection_name,
|
||||
connection.object_path,
|
||||
CONNECTION_INTERFACE_CONTACTS,
|
||||
'GetContactAttributes',
|
||||
'auasb',
|
||||
([self.contact_handle], [CONNECTION_INTERFACE_ALIASING],
|
||||
False),
|
||||
reply_handler=self.__got_attributes_cb,
|
||||
error_handler=self.__error_handler_cb)
|
||||
|
||||
def __got_properties_cb(self, properties):
|
||||
_logger.debug('__got_properties_cb %r', properties)
|
||||
|
@ -24,7 +24,7 @@ from functools import partial
|
||||
import dbus
|
||||
from dbus import PROPERTIES_IFACE
|
||||
from telepathy.interfaces import ACCOUNT, \
|
||||
ACCOUNT_MANAGER
|
||||
ACCOUNT_MANAGER
|
||||
from telepathy.constants import CONNECTION_STATUS_CONNECTED
|
||||
|
||||
ACCOUNT_MANAGER_SERVICE = 'org.freedesktop.Telepathy.AccountManager'
|
||||
@ -52,7 +52,8 @@ class ConnectionManager(object):
|
||||
for account_path in account_paths:
|
||||
obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, account_path)
|
||||
obj.connect_to_signal('AccountPropertyChanged',
|
||||
partial(self.__account_property_changed_cb, account_path))
|
||||
partial(self.__account_property_changed_cb,
|
||||
account_path))
|
||||
connection_path = obj.Get(ACCOUNT, 'Connection')
|
||||
if connection_path != '/':
|
||||
self._track_connection(account_path, connection_path)
|
||||
@ -71,9 +72,10 @@ class ConnectionManager(object):
|
||||
bus = dbus.SessionBus()
|
||||
connection = bus.get_object(connection_name, connection_path)
|
||||
connection.connect_to_signal('StatusChanged',
|
||||
partial(self.__status_changed_cb, account_path))
|
||||
partial(self.__status_changed_cb,
|
||||
account_path))
|
||||
self._connections_per_account[account_path] = \
|
||||
Connection(account_path, connection)
|
||||
Connection(account_path, connection)
|
||||
|
||||
account = bus.get_object(ACCOUNT_MANAGER_SERVICE, account_path)
|
||||
status = account.Get(ACCOUNT, 'ConnectionStatus')
|
||||
@ -112,6 +114,8 @@ class ConnectionManager(object):
|
||||
|
||||
|
||||
_connection_manager = None
|
||||
|
||||
|
||||
def get_connection_manager():
|
||||
global _connection_manager
|
||||
if not _connection_manager:
|
||||
|
@ -33,8 +33,8 @@ from sugar3.presence.activity import Activity
|
||||
from sugar3.presence.connectionmanager import get_connection_manager
|
||||
|
||||
from telepathy.interfaces import ACCOUNT, \
|
||||
ACCOUNT_MANAGER, \
|
||||
CONNECTION
|
||||
ACCOUNT_MANAGER, \
|
||||
CONNECTION
|
||||
from telepathy.constants import HANDLE_TYPE_CONTACT
|
||||
|
||||
|
||||
@ -50,8 +50,8 @@ class PresenceService(GObject.GObject):
|
||||
"""Provides simplified access to the Telepathy framework to activities"""
|
||||
__gsignals__ = {
|
||||
'activity-shared': (GObject.SignalFlags.RUN_FIRST, None,
|
||||
([GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT,
|
||||
GObject.TYPE_PYOBJECT])),
|
||||
([GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT,
|
||||
GObject.TYPE_PYOBJECT])),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
@ -78,15 +78,15 @@ class PresenceService(GObject.GObject):
|
||||
else:
|
||||
connection_manager = get_connection_manager()
|
||||
connections_per_account = \
|
||||
connection_manager.get_connections_per_account()
|
||||
connection_manager.get_connections_per_account()
|
||||
for account_path, connection in connections_per_account.items():
|
||||
if not connection.connected:
|
||||
continue
|
||||
logging.debug('Calling GetActivity on %s', account_path)
|
||||
try:
|
||||
room_handle = connection.connection.GetActivity(
|
||||
activity_id,
|
||||
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
|
||||
activity_id,
|
||||
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
|
||||
except dbus.exceptions.DBusException, e:
|
||||
name = 'org.freedesktop.Telepathy.Error.NotAvailable'
|
||||
if e.get_dbus_name() == name:
|
||||
@ -157,9 +157,10 @@ class PresenceService(GObject.GObject):
|
||||
if connection_path == tp_conn_path:
|
||||
connection_name = connection_path.replace('/', '.')[1:]
|
||||
connection = bus.get_object(connection_name, connection_path)
|
||||
contact_ids = connection.InspectHandles(HANDLE_TYPE_CONTACT,
|
||||
[handle],
|
||||
dbus_interface=CONNECTION)
|
||||
contact_ids = connection.InspectHandles(
|
||||
HANDLE_TYPE_CONTACT,
|
||||
[handle],
|
||||
dbus_interface=CONNECTION)
|
||||
return self.get_buddy(account_path, contact_ids[0])
|
||||
|
||||
raise ValueError('Unknown buddy in connection %s with handle %d',
|
||||
@ -203,7 +204,7 @@ class PresenceService(GObject.GObject):
|
||||
|
||||
connection_manager = get_connection_manager()
|
||||
account_path, connection = \
|
||||
connection_manager.get_preferred_connection()
|
||||
connection_manager.get_preferred_connection()
|
||||
|
||||
if connection is None:
|
||||
self.emit('activity-shared', False, None,
|
||||
|
@ -49,7 +49,7 @@ class SugarTubeConnection(TubeConnection):
|
||||
# It's me, just get my global handle
|
||||
handle = self._conn.GetSelfHandle()
|
||||
elif self._group_iface.GetGroupFlags() & \
|
||||
CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES:
|
||||
CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES:
|
||||
# The group (channel) has channel specific handles
|
||||
handle = self._group_iface.GetHandleOwners([cs_handle])[0]
|
||||
else:
|
||||
|
@ -62,11 +62,13 @@ class TubeConnection(Connection):
|
||||
# pylint: disable=W0201
|
||||
# Confused by __new__
|
||||
self.self_handle = handle
|
||||
match = self._tubes_iface.connect_to_signal('DBusNamesChanged',
|
||||
self._on_dbus_names_changed)
|
||||
self._tubes_iface.GetDBusNames(self.tube_id,
|
||||
reply_handler=self._on_get_dbus_names_reply,
|
||||
error_handler=self._on_get_dbus_names_error)
|
||||
match = self._tubes_iface.connect_to_signal(
|
||||
'DBusNamesChanged',
|
||||
self._on_dbus_names_changed)
|
||||
self._tubes_iface.GetDBusNames(
|
||||
self.tube_id,
|
||||
reply_handler=self._on_get_dbus_names_reply,
|
||||
error_handler=self._on_get_dbus_names_error)
|
||||
self._dbus_names_changed_match = match
|
||||
|
||||
def _on_get_self_handle_error(self, e):
|
||||
|
Loading…
Reference in New Issue
Block a user