Console ps_watcher: Log signals as well as errors.
Correctly remove activity from buddy's list when buddy leaves.
This commit is contained in:
parent
df5ebb32e0
commit
9885b892a2
@ -24,8 +24,8 @@ from gobject import timeout_add
|
|||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('ps_watcher')
|
logger = logging.getLogger('ps_watcher')
|
||||||
logging.basicConfig(filename='/tmp/ps_watcher.log')
|
#logging.basicConfig(filename='/tmp/ps_watcher.log')
|
||||||
logging.getLogger().setLevel(1)
|
#logging.getLogger().setLevel(1)
|
||||||
|
|
||||||
|
|
||||||
PS_NAME = 'org.laptop.Sugar.Presence'
|
PS_NAME = 'org.laptop.Sugar.Presence'
|
||||||
@ -107,6 +107,8 @@ class ActivityWatcher(object):
|
|||||||
return
|
return
|
||||||
if buddy.startswith('/org/laptop/Sugar/Presence/Buddies/'):
|
if buddy.startswith('/org/laptop/Sugar/Presence/Buddies/'):
|
||||||
buddy = '.../' + buddy[35:]
|
buddy = '.../' + buddy[35:]
|
||||||
|
self.ps_watcher.log('INFO: Activity %s emitted BuddyJoined("%s")',
|
||||||
|
self.object_path, buddy)
|
||||||
self.buddies.append(buddy)
|
self.buddies.append(buddy)
|
||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_BUDDIES,
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_BUDDIES,
|
||||||
' '.join(self.buddies))
|
' '.join(self.buddies))
|
||||||
@ -116,6 +118,8 @@ class ActivityWatcher(object):
|
|||||||
return
|
return
|
||||||
if buddy.startswith('/org/laptop/Sugar/Presence/Buddies/'):
|
if buddy.startswith('/org/laptop/Sugar/Presence/Buddies/'):
|
||||||
buddy = '.../' + buddy[35:]
|
buddy = '.../' + buddy[35:]
|
||||||
|
self.ps_watcher.log('INFO: Activity %s emitted BuddyLeft("%s")',
|
||||||
|
self.object_path, buddy)
|
||||||
try:
|
try:
|
||||||
self.buddies.remove(buddy)
|
self.buddies.remove(buddy)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -129,7 +133,8 @@ class ActivityWatcher(object):
|
|||||||
self._on_buddy_joined(buddy)
|
self._on_buddy_joined(buddy)
|
||||||
|
|
||||||
def _on_get_buddies_failure(self, e):
|
def _on_get_buddies_failure(self, e):
|
||||||
self.log('<Activity %s>.GetJoinedBuddies(): %s', self.object_path, e)
|
self.log('ERROR: <Activity %s>.GetJoinedBuddies(): %s',
|
||||||
|
self.object_path, e)
|
||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_BUDDIES,
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_BUDDIES,
|
||||||
'!')
|
'!')
|
||||||
|
|
||||||
@ -138,6 +143,8 @@ class ActivityWatcher(object):
|
|||||||
return
|
return
|
||||||
if channel.startswith(self.full_conn):
|
if channel.startswith(self.full_conn):
|
||||||
channel = '...' + channel[len(self.full_conn):]
|
channel = '...' + channel[len(self.full_conn):]
|
||||||
|
self.ps_watcher.log('INFO: Activity %s emitted NewChannel("%s")',
|
||||||
|
self.object_path, channel)
|
||||||
self.channels.append(channel)
|
self.channels.append(channel)
|
||||||
# FIXME: listen for Telepathy Closed signal!
|
# FIXME: listen for Telepathy Closed signal!
|
||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_CHANNELS,
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_CHANNELS,
|
||||||
@ -158,7 +165,7 @@ class ActivityWatcher(object):
|
|||||||
' '.join(self.channels))
|
' '.join(self.channels))
|
||||||
|
|
||||||
def _on_get_channels_failure(self, e):
|
def _on_get_channels_failure(self, e):
|
||||||
self.ps_watcher.log('<Activity %s>.GetChannels(): %s',
|
self.ps_watcher.log('ERROR: <Activity %s>.GetChannels(): %s',
|
||||||
self.object_path, e)
|
self.object_path, e)
|
||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_CONN,
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_CONN,
|
||||||
'!')
|
'!')
|
||||||
@ -170,7 +177,8 @@ class ActivityWatcher(object):
|
|||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_ID, ident)
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_ID, ident)
|
||||||
|
|
||||||
def _on_get_id_failure(self, e):
|
def _on_get_id_failure(self, e):
|
||||||
self.ps_watcher.log('<Activity %s>.GetId(): %s', self.object_path, e)
|
self.ps_watcher.log('ERROR: <Activity %s>.GetId(): %s',
|
||||||
|
self.object_path, e)
|
||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_ID,
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_ID,
|
||||||
'!')
|
'!')
|
||||||
|
|
||||||
@ -180,7 +188,7 @@ class ActivityWatcher(object):
|
|||||||
color)
|
color)
|
||||||
|
|
||||||
def _on_get_color_failure(self, e):
|
def _on_get_color_failure(self, e):
|
||||||
self.ps_watcher.log('<Activity %s>.GetColor(): %s',
|
self.ps_watcher.log('ERROR: <Activity %s>.GetColor(): %s',
|
||||||
self.object_path, e)
|
self.object_path, e)
|
||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_COLOR,
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_COLOR,
|
||||||
'!')
|
'!')
|
||||||
@ -191,7 +199,8 @@ class ActivityWatcher(object):
|
|||||||
type_)
|
type_)
|
||||||
|
|
||||||
def _on_get_type_failure(self, e):
|
def _on_get_type_failure(self, e):
|
||||||
self.ps_watcher.log('<Activity %s>.GetType(): %s', self.object_path, e)
|
self.ps_watcher.log('ERROR: <Activity %s>.GetType(): %s',
|
||||||
|
self.object_path, e)
|
||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_TYPE,
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_TYPE,
|
||||||
'!')
|
'!')
|
||||||
|
|
||||||
@ -201,7 +210,8 @@ class ActivityWatcher(object):
|
|||||||
name)
|
name)
|
||||||
|
|
||||||
def _on_get_name_failure(self, e):
|
def _on_get_name_failure(self, e):
|
||||||
self.ps_watcher.log('<Activity %s>.GetName(): %s', self.object_path, e)
|
self.ps_watcher.log('ERROR: <Activity %s>.GetName(): %s',
|
||||||
|
self.object_path, e)
|
||||||
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_NAME,
|
self.ps_watcher.activities_list_store.set(self.iter, ACT_COL_NAME,
|
||||||
'!')
|
'!')
|
||||||
|
|
||||||
@ -266,6 +276,9 @@ class BuddyWatcher(object):
|
|||||||
def _on_handle_added(self, service, conn, handle):
|
def _on_handle_added(self, service, conn, handle):
|
||||||
if self.handles is None:
|
if self.handles is None:
|
||||||
return
|
return
|
||||||
|
self.ps_watcher.log('INFO: Buddy %s emitted HandleAdded("%s", '
|
||||||
|
'"%s", %u)', self.object_path, service, conn,
|
||||||
|
handle)
|
||||||
if conn.startswith('/org/freedesktop/Telepathy/Connection/'):
|
if conn.startswith('/org/freedesktop/Telepathy/Connection/'):
|
||||||
conn = '.../' + conn[38:]
|
conn = '.../' + conn[38:]
|
||||||
self.handles.append('%u@%s' % (handle, conn))
|
self.handles.append('%u@%s' % (handle, conn))
|
||||||
@ -278,8 +291,11 @@ class BuddyWatcher(object):
|
|||||||
return
|
return
|
||||||
if conn.startswith('/org/freedesktop/Telepathy/Connection/'):
|
if conn.startswith('/org/freedesktop/Telepathy/Connection/'):
|
||||||
conn = '.../' + conn[38:]
|
conn = '.../' + conn[38:]
|
||||||
|
self.ps_watcher.log('INFO: Buddy %s emitted HandleRemoved("%s", '
|
||||||
|
'"%s", %u)', self.object_path, service, conn,
|
||||||
|
handle)
|
||||||
try:
|
try:
|
||||||
self.handles.append('%u@%s' % (handle, conn))
|
self.handles.remove('%u@%s' % (handle, conn))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_HANDLES,
|
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_HANDLES,
|
||||||
@ -291,7 +307,8 @@ class BuddyWatcher(object):
|
|||||||
self._on_handle_added(service, conn, handle)
|
self._on_handle_added(service, conn, handle)
|
||||||
|
|
||||||
def _on_get_handles_failure(self, e):
|
def _on_get_handles_failure(self, e):
|
||||||
self.log('<Buddy %s>.GetTelepathyHandles(): %s', self.object_path, e)
|
self.log('ERROR: <Buddy %s>.GetTelepathyHandles(): %s',
|
||||||
|
self.object_path, e)
|
||||||
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_HANDLES,
|
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_HANDLES,
|
||||||
'!')
|
'!')
|
||||||
|
|
||||||
@ -300,6 +317,8 @@ class BuddyWatcher(object):
|
|||||||
return
|
return
|
||||||
if act.startswith('/org/laptop/Sugar/Presence/Activities/'):
|
if act.startswith('/org/laptop/Sugar/Presence/Activities/'):
|
||||||
act = '.../' + act[38:]
|
act = '.../' + act[38:]
|
||||||
|
self.ps_watcher.log('INFO: Buddy %s emitted ActivityJoined("%s")',
|
||||||
|
self.object_path, act)
|
||||||
self.activities.append(act)
|
self.activities.append(act)
|
||||||
self.ps_watcher.buddies_list_store.set(self.iter,
|
self.ps_watcher.buddies_list_store.set(self.iter,
|
||||||
BUDDY_COL_ACTIVITIES,
|
BUDDY_COL_ACTIVITIES,
|
||||||
@ -308,6 +327,10 @@ class BuddyWatcher(object):
|
|||||||
def _on_left(self, act):
|
def _on_left(self, act):
|
||||||
if self.activities is None:
|
if self.activities is None:
|
||||||
return
|
return
|
||||||
|
if act.startswith('/org/laptop/Sugar/Presence/Activities/'):
|
||||||
|
act = '.../' + act[38:]
|
||||||
|
self.ps_watcher.log('INFO: Buddy %s emitted ActivityLeft("%s")',
|
||||||
|
self.object_path, act)
|
||||||
try:
|
try:
|
||||||
self.activities.remove(act)
|
self.activities.remove(act)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -321,7 +344,8 @@ class BuddyWatcher(object):
|
|||||||
self._on_joined(act)
|
self._on_joined(act)
|
||||||
|
|
||||||
def _on_get_acts_failure(self, e):
|
def _on_get_acts_failure(self, e):
|
||||||
self.log('<Buddy %s>.GetJoinedActivities(): %s', self.object_path, e)
|
self.log('ERROR: <Buddy %s>.GetJoinedActivities(): %s',
|
||||||
|
self.object_path, e)
|
||||||
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_ACTIVITIES,
|
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_ACTIVITIES,
|
||||||
'!')
|
'!')
|
||||||
|
|
||||||
@ -352,7 +376,7 @@ class BuddyWatcher(object):
|
|||||||
self.keyid)
|
self.keyid)
|
||||||
|
|
||||||
def _on_get_props_failure(self, e):
|
def _on_get_props_failure(self, e):
|
||||||
self.ps_watcher.log('<Buddy %s>.GetProperties(): %s',
|
self.ps_watcher.log('ERROR: <Buddy %s>.GetProperties(): %s',
|
||||||
self.object_path, e)
|
self.object_path, e)
|
||||||
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_NICK, '!')
|
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_NICK, '!')
|
||||||
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_OWNER,
|
self.ps_watcher.buddies_list_store.set(self.iter, BUDDY_COL_OWNER,
|
||||||
@ -386,15 +410,12 @@ class PresenceServiceWatcher(VBox):
|
|||||||
def __init__(self, bus, unique_name, log):
|
def __init__(self, bus, unique_name, log):
|
||||||
VBox.__init__(self)
|
VBox.__init__(self)
|
||||||
|
|
||||||
logger.debug('Starting up PresenceServiceWatcher...')
|
|
||||||
self.bus = bus
|
self.bus = bus
|
||||||
self.unique_name = unique_name
|
self.unique_name = unique_name
|
||||||
self.proxy = bus.get_object(unique_name, PS_PATH)
|
self.proxy = bus.get_object(unique_name, PS_PATH)
|
||||||
self.iface = dbus.Interface(self.proxy, PS_IFACE)
|
self.iface = dbus.Interface(self.proxy, PS_IFACE)
|
||||||
self.log = log
|
self.log = log
|
||||||
|
|
||||||
logger.debug('Starting up PresenceServiceWatcher (2)...')
|
|
||||||
|
|
||||||
self.activities = None
|
self.activities = None
|
||||||
self.iface.connect_to_signal('ActivityAppeared',
|
self.iface.connect_to_signal('ActivityAppeared',
|
||||||
self._on_activity_appeared)
|
self._on_activity_appeared)
|
||||||
@ -529,13 +550,13 @@ class PresenceServiceWatcher(VBox):
|
|||||||
self._on_private_invitation)
|
self._on_private_invitation)
|
||||||
|
|
||||||
def _on_get_activities_success(self, paths):
|
def _on_get_activities_success(self, paths):
|
||||||
logger.debug('PS GetActivities() returned %r', paths)
|
self.log('INFO: PS GetActivities() returned %r', paths)
|
||||||
self.activities = {}
|
self.activities = {}
|
||||||
for path in paths:
|
for path in paths:
|
||||||
self.activities[path] = ActivityWatcher(self, path)
|
self.activities[path] = ActivityWatcher(self, path)
|
||||||
|
|
||||||
def _on_get_activities_failure(self, e):
|
def _on_get_activities_failure(self, e):
|
||||||
self.log('PS GetActivities() failed with %s', e)
|
self.log('ERROR: PS GetActivities() failed with %s', e)
|
||||||
|
|
||||||
def add_activity(self, act):
|
def add_activity(self, act):
|
||||||
path = act.object_path
|
path = act.object_path
|
||||||
@ -551,36 +572,36 @@ class PresenceServiceWatcher(VBox):
|
|||||||
def _on_activity_appeared(self, path):
|
def _on_activity_appeared(self, path):
|
||||||
if self.activities is None:
|
if self.activities is None:
|
||||||
return
|
return
|
||||||
logger.debug('PS emitted ActivityAppeared("%s")', path)
|
self.log('INFO: PS emitted ActivityAppeared("%s")', path)
|
||||||
self.activities[path] = ActivityWatcher(self, path)
|
self.activities[path] = ActivityWatcher(self, path)
|
||||||
|
|
||||||
def _on_activity_disappeared(self, path):
|
def _on_activity_disappeared(self, path):
|
||||||
if self.activities is None:
|
if self.activities is None:
|
||||||
return
|
return
|
||||||
logger.debug('PS emitted ActivityDisappeared("%s")', path)
|
self.log('INFO: PS emitted ActivityDisappeared("%s")', path)
|
||||||
act = self.activities.get(path)
|
act = self.activities.get(path)
|
||||||
if act is None:
|
if act is None:
|
||||||
self.log('Trying to remove activity "%s" which is already '
|
self.log('WARNING: Trying to remove activity "%s" which is '
|
||||||
'absent', path)
|
'already absent', path)
|
||||||
else:
|
else:
|
||||||
# we don't remove the activity straight away, just cross it out
|
# we don't remove the activity straight away, just cross it out
|
||||||
act.disappear()
|
act.disappear()
|
||||||
|
|
||||||
def _on_activity_invitation(self, path):
|
def _on_activity_invitation(self, path):
|
||||||
logger.debug('PS emitted ActivityInvitation("%s")', path)
|
self.log('INFO: PS emitted ActivityInvitation("%s")', path)
|
||||||
|
|
||||||
def _on_private_invitation(self, bus_name, conn, channel):
|
def _on_private_invitation(self, bus_name, conn, channel):
|
||||||
logger.debug('PS emitted PrivateInvitation("%s", "%s", "%s")',
|
self.log('INFO: PS emitted PrivateInvitation("%s", "%s", "%s")',
|
||||||
bus_name, conn, channel)
|
bus_name, conn, channel)
|
||||||
|
|
||||||
def _on_get_buddies_success(self, paths):
|
def _on_get_buddies_success(self, paths):
|
||||||
logger.debug('PS GetBuddies() returned %r', paths)
|
self.log('INFO: PS GetBuddies() returned %r', paths)
|
||||||
self.buddies = {}
|
self.buddies = {}
|
||||||
for path in paths:
|
for path in paths:
|
||||||
self.buddies[path] = BuddyWatcher(self, path)
|
self.buddies[path] = BuddyWatcher(self, path)
|
||||||
|
|
||||||
def _on_get_buddies_failure(self, e):
|
def _on_get_buddies_failure(self, e):
|
||||||
self.log('PS GetBuddies() failed with %s', e)
|
self.log('ERROR: PS GetBuddies() failed with %s', e)
|
||||||
|
|
||||||
def add_buddy(self, b):
|
def add_buddy(self, b):
|
||||||
path = b.object_path
|
path = b.object_path
|
||||||
@ -597,16 +618,16 @@ class PresenceServiceWatcher(VBox):
|
|||||||
def _on_buddy_appeared(self, path):
|
def _on_buddy_appeared(self, path):
|
||||||
if self.buddies is None:
|
if self.buddies is None:
|
||||||
return
|
return
|
||||||
logger.debug('PS emitted BuddyAppeared("%s")', path)
|
self.log('INFO: PS emitted BuddyAppeared("%s")', path)
|
||||||
self.buddies[path] = BuddyWatcher(self, path)
|
self.buddies[path] = BuddyWatcher(self, path)
|
||||||
|
|
||||||
def _on_buddy_disappeared(self, path):
|
def _on_buddy_disappeared(self, path):
|
||||||
if self.buddies is None:
|
if self.buddies is None:
|
||||||
return
|
return
|
||||||
logger.debug('PS emitted BuddyDisappeared("%s")', path)
|
self.log('INFO: PS emitted BuddyDisappeared("%s")', path)
|
||||||
b = self.buddies.get(path)
|
b = self.buddies.get(path)
|
||||||
if b is None:
|
if b is None:
|
||||||
self.log('Trying to remove buddy "%s" which is already '
|
self.log('ERROR: Trying to remove buddy "%s" which is already '
|
||||||
'absent', path)
|
'absent', path)
|
||||||
else:
|
else:
|
||||||
# we don't remove the activity straight away, just cross it out
|
# we don't remove the activity straight away, just cross it out
|
||||||
@ -624,7 +645,7 @@ class PresenceServiceNameWatcher(VBox):
|
|||||||
self.errors = ListStore(str)
|
self.errors = ListStore(str)
|
||||||
|
|
||||||
errors = TreeView(model=self.errors)
|
errors = TreeView(model=self.errors)
|
||||||
errors.insert_column_with_attributes(0, 'Errors', CellRendererText(),
|
errors.insert_column_with_attributes(0, 'Log', CellRendererText(),
|
||||||
text=0)
|
text=0)
|
||||||
scroller = ScrolledWindow()
|
scroller = ScrolledWindow()
|
||||||
scroller.add(errors)
|
scroller.add(errors)
|
||||||
@ -662,7 +683,7 @@ class PresenceServiceNameWatcher(VBox):
|
|||||||
self.ps_watcher = Label('-')
|
self.ps_watcher = Label('-')
|
||||||
self.paned.pack2(self.ps_watcher)
|
self.paned.pack2(self.ps_watcher)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log('%s', e)
|
self.log('ERROR: %s', e)
|
||||||
|
|
||||||
|
|
||||||
class Interface(object):
|
class Interface(object):
|
||||||
|
Loading…
Reference in New Issue
Block a user