Make contact-online handler async; print -> logging.debug

This commit is contained in:
Dan Williams 2007-04-10 15:00:49 -04:00
parent 89ec9195e9
commit 8d4d87a081

View File

@ -121,11 +121,11 @@ class ServerPlugin(gobject.GObject):
self._reconnect_id = 0 self._reconnect_id = 0
def _owner_property_changed_cb(self, owner, properties): def _owner_property_changed_cb(self, owner, properties):
print "Owner properties changed: %s" % properties logging.debug("Owner properties changed: %s" % properties)
self._set_self_buddy_info() self._set_self_buddy_info()
def _owner_icon_changed_cb(self, owner, icon): def _owner_icon_changed_cb(self, owner, icon):
print "Owner icon changed to size %d" % len(str(icon)) logging.debug("Owner icon changed to size %d" % len(str(icon)))
self._upload_avatar() self._upload_avatar()
def _get_account_info(self): def _get_account_info(self):
@ -146,7 +146,6 @@ class ServerPlugin(gobject.GObject):
account_info['account'] = "%s@%s" % (khash, account_info['server']) account_info['account'] = "%s@%s" % (khash, account_info['server'])
account_info['password'] = profile.get_private_key_hash() account_info['password'] = profile.get_private_key_hash()
print account_info
return account_info return account_info
def _find_existing_connection(self): def _find_existing_connection(self):
@ -233,7 +232,7 @@ class ServerPlugin(gobject.GObject):
subscribe[CHANNEL_INTERFACE_GROUP].AddMembers([self_handle], '') subscribe[CHANNEL_INTERFACE_GROUP].AddMembers([self_handle], '')
if CONN_INTERFACE_BUDDY_INFO not in self._conn.get_valid_interfaces(): if CONN_INTERFACE_BUDDY_INFO not in self._conn.get_valid_interfaces():
print 'OLPC information not available' logging.debug('OLPC information not available')
self.cleanup() self.cleanup()
return return
@ -250,7 +249,7 @@ class ServerPlugin(gobject.GObject):
try: try:
self._set_self_buddy_info() self._set_self_buddy_info()
except RuntimeError, e: except RuntimeError, e:
print e logging.debug("Could not set owner properties: %s" % e)
self.cleanup() self.cleanup()
return return
@ -273,7 +272,7 @@ class ServerPlugin(gobject.GObject):
types, minw, minh, maxw, maxh, maxsize = self._conn[CONN_INTERFACE_AVATARS].GetAvatarRequirements() types, minw, minh, maxw, maxh, maxsize = self._conn[CONN_INTERFACE_AVATARS].GetAvatarRequirements()
if not "image/jpeg" in types: if not "image/jpeg" in types:
print "server does not accept JPEG format avatars." logging.debug("server does not accept JPEG format avatars.")
return return
img_data = _get_buddy_icon_at_size(icon_data, min(maxw, 96), min(maxh, 96), maxsize) img_data = _get_buddy_icon_at_size(icon_data, min(maxw, 96), min(maxh, 96), maxsize)
@ -288,7 +287,7 @@ class ServerPlugin(gobject.GObject):
self._activities[act] = handle self._activities[act] = handle
if (act, handle) in self._joined_activities: if (act, handle) in self._joined_activities:
print "%s already joined" % act logging.debug("Already joined %s" % act)
return return
chan_path = self._conn[CONN_INTERFACE].RequestChannel( chan_path = self._conn[CONN_INTERFACE].RequestChannel(
@ -327,7 +326,7 @@ class ServerPlugin(gobject.GObject):
if not cur_activity_handle: if not cur_activity_handle:
# dont advertise a current activity that's not shared # dont advertise a current activity that's not shared
cur_activity = "" cur_activity = ""
print "cur_activity is '%s', handle is %s" % (cur_activity, cur_activity_handle) logging.debug("cur_activity is '%s', handle is %s" % (cur_activity, cur_activity_handle))
self._conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity, cur_activity_handle) self._conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity, cur_activity_handle)
self._upload_avatar() self._upload_avatar()
@ -340,13 +339,13 @@ class ServerPlugin(gobject.GObject):
def _status_changed_cb(self, state, reason): def _status_changed_cb(self, state, reason):
if state == CONNECTION_STATUS_CONNECTING: if state == CONNECTION_STATUS_CONNECTING:
print 'connecting: %r' % reason logging.debug("State: connecting...")
elif state == CONNECTION_STATUS_CONNECTED: elif state == CONNECTION_STATUS_CONNECTED:
print 'connected: %r' % reason logging.debug("State: connected")
self._connected_cb() self._connected_cb()
self.emit('status', state, int(reason)) self.emit('status', state, int(reason))
elif state == CONNECTION_STATUS_DISCONNECTED: elif state == CONNECTION_STATUS_DISCONNECTED:
print 'disconnected: %r' % reason logging.debug("State: disconnected (reason %r)" % reason)
self.emit('status', state, int(reason)) self.emit('status', state, int(reason))
self._conn = None self._conn = None
if reason == CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED: if reason == CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
@ -355,7 +354,7 @@ class ServerPlugin(gobject.GObject):
return False return False
def start(self): def start(self):
print "Trying to connect..." logging.debug("Starting up...")
# If the connection is already connected query initial contacts # If the connection is already connected query initial contacts
conn_status = self._conn[CONN_INTERFACE].GetStatus() conn_status = self._conn[CONN_INTERFACE].GetStatus()
if conn_status == CONNECTION_STATUS_CONNECTED: if conn_status == CONNECTION_STATUS_CONNECTED:
@ -379,7 +378,7 @@ class ServerPlugin(gobject.GObject):
return False return False
def _connect_error_cb(self, exception): def _connect_error_cb(self, exception):
print "Connect error: %s" % exception logging.debug("Connect error: %s" % exception)
if not self._reconnect_id: if not self._reconnect_id:
self._reconnect_id = gobject.timeout_add(10000, self._reconnect) self._reconnect_id = gobject.timeout_add(10000, self._reconnect)
@ -392,36 +391,52 @@ class ServerPlugin(gobject.GObject):
self.emit("contact-offline", handle) self.emit("contact-offline", handle)
del self._online_contacts[handle] del self._online_contacts[handle]
def _contact_online(self, handle): def _contact_online_activities_cb(self, handle, activities):
try: if not activities or not len(activities):
props = self._conn[CONN_INTERFACE_BUDDY_INFO].GetProperties(handle) logging.debug("Handle %s - No activities" % handle)
except dbus.DBusException, e: return
if str(e).startswith("org.freedesktop.DBus.Error.NoReply"): self._buddy_activities_changed_cb(handle, activities)
raise InvalidBuddyError("couldn't get properties")
props = {}
logging.debug("Error getting buddy properties: %s" % e)
if not props.has_key('color'): def _contact_online_activities_error_cb(self, handle, err):
raise InvalidBuddyError("no color") logging.debug("Handle %s - Error getting activities: %s" % (handle, err))
def _contact_online_aliases_cb(self, handle, props, aliases):
if not aliases or not len(aliases):
logging.debug("Handle %s - No aliases" % handle)
return
props['nick'] = aliases[0]
jid = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, [handle])[0]
self._online_contacts[handle] = jid
self.emit("contact-online", handle, props)
self._conn[CONN_INTERFACE_BUDDY_INFO].GetActivities(handle,
reply_handler=lambda *args: self._contact_online_activities_cb(handle, *args),
error_handler=lambda *args: self._contact_online_activities_error_cb(handle, *args))
def _contact_online_aliases_error_cb(self, handle, err):
logging.debug("Handle %s - Error getting nickname: %s" % (handle, err))
def _contact_online_properties_cb(self, handle, props):
if not props.has_key('key'): if not props.has_key('key'):
raise InvalidBuddyError("no key") logging.debug("Handle %s - invalid key." % handle)
if not props.has_key('color'):
logging.debug("Handle %s - invalid color." % handle)
# Convert key from dbus byte array to python string # Convert key from dbus byte array to python string
props["key"] = psutils.bytes_to_string(props["key"]) props["key"] = psutils.bytes_to_string(props["key"])
jid = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, [handle])[0] self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle],
nick = self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle])[0] reply_handler=lambda *args: self._contact_online_aliases_cb(handle, props, *args),
if not nick: error_handler=lambda *args: self._contact_online_aliases_error_cb(handle, *args))
raise InvalidBuddyError("no name")
props['nick'] = nick def _contact_online_properties_error_cb(self, handle, err):
logging.debug("Handle %s - Error getting properties: %s" % (handle, err))
self._online_contacts[handle] = jid def _contact_online(self, handle):
# Any properties that are returned by TP as dbus.ByteArray or dbus.Array self._conn[CONN_INTERFACE_BUDDY_INFO].GetProperties(handle,
# must be converted before emitting signals reply_handler=lambda *args: self._contact_online_properties_cb(handle, *args),
self.emit("contact-online", handle, props) error_handler=lambda *args: self._contact_online_properties_error_cb(handle, *args))
activities = self._conn[CONN_INTERFACE_BUDDY_INFO].GetActivities(handle)
self._buddy_activities_changed_cb(handle, activities)
def _presence_update_cb(self, presence): def _presence_update_cb(self, presence):
for handle in presence: for handle in presence:
@ -431,12 +446,9 @@ class ServerPlugin(gobject.GObject):
jid = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, [handle])[0] jid = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, [handle])[0]
olstr = "ONLINE" olstr = "ONLINE"
if not online: olstr = "OFFLINE" if not online: olstr = "OFFLINE"
print "Handle %s (%s) was %s, status now '%s'." % (handle, jid, olstr, status) logging.debug("Handle %s (%s) was %s, status now '%s'." % (handle, jid, olstr, status))
if not online and status in ["available", "away", "brb", "busy", "dnd", "xa"]: if not online and status in ["available", "away", "brb", "busy", "dnd", "xa"]:
try: self._contact_online(handle)
self._contact_online(handle)
except InvalidBuddyError, e:
print "Not adding %s because %s" % (handle, e)
elif online and status in ["offline", "invisible"]: elif online and status in ["offline", "invisible"]:
self._contact_offline(handle) self._contact_offline(handle)
@ -514,7 +526,7 @@ class ServerPlugin(gobject.GObject):
handle = self._activities.get(act_id) handle = self._activities.get(act_id)
if not handle: if not handle:
print "set_activity_properties: handle unkown" logging.debug("set_activity_properties: handle unkown")
return return
self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].SetProperties(handle, props) self._conn[CONN_INTERFACE_ACTIVITY_PROPERTIES].SetProperties(handle, props)