[telepathy-ashes/master] Better debugging messages for groups.
David Laban
david.laban at collabora.co.uk
Wed Oct 7 11:10:33 PDT 2009
By listening to MembersChangedDetailed instead of MembersChanged,
I can more often print the contact's string ID rather than just
the handle.
---
ashes/tools/groups.py | 64 +++++++++++++++++++++++++++++++++++++++----------
1 files changed, 51 insertions(+), 13 deletions(-)
diff --git a/ashes/tools/groups.py b/ashes/tools/groups.py
index 4053912..622b5c4 100644
--- a/ashes/tools/groups.py
+++ b/ashes/tools/groups.py
@@ -23,24 +23,62 @@ class ContactAcceptor(ChannelListener):
'LocalPendingMembers', reply_handler=self.local_pending, error_handler=printer)
def local_pending(self, pending):
+ """
+ Callback for get_property(LocalPendingMembers).
+ FIXME: doesn't provide the member-ids mapping, which makes printing
+ more tricky. This would be best fixed by having a more useful
+ handles_to_ids function on the connection listener object.
+ """
for handle, actor, reason, message in pending:
- self.MembersChanged(message, [], [], [handle], [], actor, reason)
+ details = {}
+ self.MembersChangedDetailed([], [], [handle], [], details)
- def MembersChanged(self, message, added, removed, local_pending, remote_pending,
- actor, reason):
+ def MembersChanged(self, message, added, removed, local_pending,
+ remote_pending, actor, reason):
+ """
+ We don't use this signal. This method just silences things.
+ #FIXME: The new API should simply avoid registering this signal handler.
+ Also, we should check if GroupFlags.Members_Changed_Detailed is set,
+ and actually handle this signal if not.
+ """
+ pass
+
+
+ def MembersChangedDetailed(self, added, removed,
+ local_pending, remote_pending, details):
+ member_ids = details.get("member-ids", {})
+ actor = details.get("actor", "nobody")
+ actor = member_ids.get(actor, actor)
if added:
- print green("Members added to "+self.id), added,
- print actor, reason, message
+ # TODO: re-factor this into a function?
+ print green("Members added to %s:"%self.id),
+ print handles_to_ids(added, member_ids),
+ print "at the request of:", actor
if removed:
- print green("Members removed from "+self.id), removed,
- print actor, reason, message
+ print green("Members removed from %s:"%self.id),
+ print handles_to_ids(removed, member_ids),
+ print "at the request of:", actor
if local_pending:
- print green("Allowing members to join "+self.id), local_pending,
- print actor, reason, message
+ print green("Allowing members to join %s:"%self.id),
+ print handles_to_ids(local_pending, member_ids),
+ print "at the request of:", actor
self.channel[telepathy.CHANNEL_INTERFACE_GROUP].AddMembers(local_pending, '')
if remote_pending:
- print green('Members invited to '+self.id), remote_pending,
- print actor, reason, message
+ print green("Members invited to %s:"%self.id),
+ print handles_to_ids(remote_pending, member_ids),
+ print "at the request of:", actor
+
+
+def handles_to_ids(handles, member_ids={}):
+ """
+ Maps contact handles to string ids for printing. This should probably be
+ available as a generic function in python, but oh well...
+ Actually, having a shortcutting method on the connection object would
+ be kinda useful, but I'm too lazy to implement it right yet.
+ """
+ ret = []
+ for handle in handles:
+ id = member_ids.get(handle, int(handle))
+ ret.append(str(id))
+ return ret
- def MembersChangedDetailed(self, Added, Removed, Local_Pending, Remote_Pending, Details):
- pass
\ No newline at end of file
--
1.5.6.5
More information about the telepathy-commits
mailing list