Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2007-08-30 10:01:03 (GMT)
committer Simon McVittie <simon.mcvittie@collabora.co.uk>2007-08-30 10:01:03 (GMT)
commit31a044e763ba3e6f5b82b3d86f88be25357f8b80 (patch)
tree79ee96fe3ba657bfa4c5ed2af40f74fe46a5692d
parent3fa97df4214cda1daa2a343da40ea9b523d4f89c (diff)
Move NotFoundError to psutils; add NotJoinedError and WrongConnectionError.
Make BUDDY_PATH public too.
-rw-r--r--src/activity.py2
-rw-r--r--src/buddy.py6
-rw-r--r--src/presenceservice.py59
-rw-r--r--src/psutils.py24
4 files changed, 48 insertions, 43 deletions
diff --git a/src/activity.py b/src/activity.py
index c23cb02..e85d314 100644
--- a/src/activity.py
+++ b/src/activity.py
@@ -29,6 +29,8 @@ from telepathy.interfaces import (CHANNEL_INTERFACE, CHANNEL_INTERFACE_GROUP,
CHANNEL_TYPE_TEXT, CONN_INTERFACE,
PROPERTIES_INTERFACE)
+from psutils import NotFoundError, NotJoinedError, WrongConnectionError
+
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
diff --git a/src/buddy.py b/src/buddy.py
index 720da2d..d41e1b4 100644
--- a/src/buddy.py
+++ b/src/buddy.py
@@ -41,7 +41,7 @@ from buddyiconcache import buddy_icon_cache
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
-_BUDDY_PATH = "/org/laptop/Sugar/Presence/Buddies/"
+BUDDY_PATH = "/org/laptop/Sugar/Presence/Buddies/"
_BUDDY_INTERFACE = "org.laptop.Sugar.Presence.Buddy"
_PROP_NICK = "nick"
@@ -174,12 +174,12 @@ class Buddy(ExportedGObject):
key-ID or JID
kwargs -- used to initialize the object's properties
- constructs a DBUS "object path" from the _BUDDY_PATH
+ constructs a DBUS "object path" from the BUDDY_PATH
and object_id
"""
self._object_id = object_id
- self._object_path = dbus.ObjectPath(_BUDDY_PATH + object_id)
+ self._object_path = dbus.ObjectPath(BUDDY_PATH + object_id)
#: activity ID -> activity
self._activities = {}
diff --git a/src/presenceservice.py b/src/presenceservice.py
index cc1b063..13f1342 100644
--- a/src/presenceservice.py
+++ b/src/presenceservice.py
@@ -23,7 +23,6 @@ from weakref import WeakValueDictionary
import dbus
import dbus.service
import gobject
-from dbus.exceptions import DBusException
from dbus.gobject_service import ExportedGObject
from dbus.mainloop.glib import DBusGMainLoop
from telepathy.client import ManagerRegistry, Connection
@@ -37,25 +36,19 @@ from sugar import util
from server_plugin import ServerPlugin
from linklocal_plugin import LinkLocalPlugin
-from buddy import Buddy, ShellOwner
+from buddy import Buddy, ShellOwner, BUDDY_PATH
from activity import Activity
-from psutils import pubkey_to_keyid
+from psutils import pubkey_to_keyid, NotFoundError, PRESENCE_INTERFACE
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
_PRESENCE_SERVICE = "org.laptop.Sugar.Presence"
-_PRESENCE_INTERFACE = "org.laptop.Sugar.Presence"
_PRESENCE_PATH = "/org/laptop/Sugar/Presence"
_logger = logging.getLogger('s-p-s.presenceservice')
-class NotFoundError(DBusException):
- def __init__(self, msg):
- DBusException.__init__(self, msg)
- self._dbus_error_name = _PRESENCE_INTERFACE + '.NotFound'
-
class PresenceService(ExportedGObject):
__gtype_name__ = "PresenceService"
@@ -545,31 +538,31 @@ class PresenceService(ExportedGObject):
self.PrivateInvitation(str(conn.service_name), conn.object_path,
chan_path)
- @dbus.service.signal(_PRESENCE_INTERFACE, signature="o")
+ @dbus.service.signal(PRESENCE_INTERFACE, signature="o")
def ActivityAppeared(self, activity):
pass
- @dbus.service.signal(_PRESENCE_INTERFACE, signature="o")
+ @dbus.service.signal(PRESENCE_INTERFACE, signature="o")
def ActivityDisappeared(self, activity):
pass
- @dbus.service.signal(_PRESENCE_INTERFACE, signature="o")
+ @dbus.service.signal(PRESENCE_INTERFACE, signature="o")
def BuddyAppeared(self, buddy):
pass
- @dbus.service.signal(_PRESENCE_INTERFACE, signature="o")
+ @dbus.service.signal(PRESENCE_INTERFACE, signature="o")
def BuddyDisappeared(self, buddy):
pass
- @dbus.service.signal(_PRESENCE_INTERFACE, signature="o")
+ @dbus.service.signal(PRESENCE_INTERFACE, signature="o")
def ActivityInvitation(self, activity):
pass
- @dbus.service.signal(_PRESENCE_INTERFACE, signature="soo")
+ @dbus.service.signal(PRESENCE_INTERFACE, signature="soo")
def PrivateInvitation(self, bus_name, connection, channel):
pass
- @dbus.service.method(_PRESENCE_INTERFACE, in_signature='',
+ @dbus.service.method(PRESENCE_INTERFACE, in_signature='',
out_signature="ao")
def GetActivities(self):
ret = []
@@ -578,7 +571,7 @@ class PresenceService(ExportedGObject):
ret.append(act.object_path())
return ret
- @dbus.service.method(_PRESENCE_INTERFACE, in_signature="s",
+ @dbus.service.method(PRESENCE_INTERFACE, in_signature="s",
out_signature="o")
def GetActivityById(self, actid):
act = self._activities_by_id.get(actid, None)
@@ -586,7 +579,7 @@ class PresenceService(ExportedGObject):
raise NotFoundError("The activity was not found.")
return act.object_path()
- @dbus.service.method(_PRESENCE_INTERFACE, in_signature='',
+ @dbus.service.method(PRESENCE_INTERFACE, in_signature='',
out_signature="ao")
def GetBuddies(self):
# in the presence of an out_signature, dbus-python will convert
@@ -603,7 +596,7 @@ class PresenceService(ExportedGObject):
ret.add(buddy)
return ret
- @dbus.service.method(_PRESENCE_INTERFACE,
+ @dbus.service.method(PRESENCE_INTERFACE,
in_signature="ay", out_signature="o",
byte_arrays=True)
def GetBuddyByPublicKey(self, key):
@@ -618,7 +611,7 @@ class PresenceService(ExportedGObject):
return buddy.object_path()
raise NotFoundError("The buddy was not found.")
- @dbus.service.method(_PRESENCE_INTERFACE, in_signature='sou',
+ @dbus.service.method(PRESENCE_INTERFACE, in_signature='sou',
out_signature='o')
def GetBuddyByTelepathyHandle(self, tp_conn_name, tp_conn_path, handle):
"""Get the buddy corresponding to a Telepathy handle.
@@ -696,7 +689,7 @@ class PresenceService(ExportedGObject):
handle_to_buddy[handle] = buddy
return ret
- @dbus.service.method(_PRESENCE_INTERFACE,
+ @dbus.service.method(PRESENCE_INTERFACE,
in_signature='', out_signature="o")
def GetOwner(self):
if not self._owner:
@@ -704,35 +697,23 @@ class PresenceService(ExportedGObject):
else:
return self._owner.object_path()
- @dbus.service.method(_PRESENCE_INTERFACE, in_signature="sssa{sv}",
+ @dbus.service.method(PRESENCE_INTERFACE, in_signature="sssa{sv}",
out_signature="o", async_callbacks=('async_cb', 'async_err_cb'))
def ShareActivity(self, actid, atype, name, properties, async_cb,
async_err_cb):
- _logger.warning('ShareActivity deprecated, use AdvertiseActivity')
- self._share_activity(actid, atype, name, properties, False,
- async_cb, async_err_cb)
-
- @dbus.service.method(_PRESENCE_INTERFACE, in_signature="sssa{sv}",
- out_signature="o", async_callbacks=('async_cb', 'async_err_cb'))
- def AdvertiseActivity(self, actid, atype, name, properties, async_cb,
- async_err_cb):
+ # FIXME: this makes all activities start off public.
+ # Once mutable properties have landed in sugar.presence, we should
+ # change the default to private=True.
self._share_activity(actid, atype, name, properties, False,
async_cb, async_err_cb)
- @dbus.service.method(_PRESENCE_INTERFACE, in_signature="sssa{sv}",
- out_signature="o", async_callbacks=('async_cb', 'async_err_cb'))
- def InviteActivity(self, actid, atype, name, properties, async_cb,
- async_err_cb):
- self._share_activity(actid, atype, name, properties, True,
- async_cb, async_err_cb)
-
def _get_preferred_plugin(self):
for tp in self._plugins:
if tp in self._connected_plugins:
return tp
return None
- @dbus.service.method(_PRESENCE_INTERFACE,
+ @dbus.service.method(PRESENCE_INTERFACE,
in_signature='', out_signature="so")
def GetPreferredConnection(self):
tp = self._get_preferred_plugin()
@@ -745,7 +726,7 @@ class PresenceService(ExportedGObject):
for tp in self._handles_buddies:
tp.cleanup()
- def _share_activity(self, actid, atype, name, properties, private,
+ def _share_activity(self, actid, atype, name, properties, private,
async_cb, async_err_cb):
"""Create the shared Activity.
diff --git a/src/psutils.py b/src/psutils.py
index 25b24b9..7863535 100644
--- a/src/psutils.py
+++ b/src/psutils.py
@@ -24,6 +24,7 @@ except ImportError:
from sha import new as sha1
import dbus
+from dbus.exceptions import DBusException
import gobject
@@ -32,6 +33,27 @@ _logger = logging.getLogger('s-p-s.psutils')
_ASCII_ALNUM = ascii_letters + digits
+PRESENCE_INTERFACE = "org.laptop.Sugar.Presence"
+
+
+class NotJoinedError(DBusException):
+ def __init__(self, msg):
+ DBusException.__init__(self, msg)
+ self._dbus_error_name = PRESENCE_INTERFACE + '.NotJoined'
+
+
+class NotFoundError(DBusException):
+ def __init__(self, msg):
+ DBusException.__init__(self, msg)
+ self._dbus_error_name = PRESENCE_INTERFACE + '.NotFound'
+
+
+class WrongConnectionError(DBusException):
+ def __init__(self, msg):
+ DBusException.__init__(self, msg)
+ self._dbus_error_name = PRESENCE_INTERFACE + '.WrongConnection'
+
+
def pubkey_to_keyid(key):
"""Return the key ID for the given public key. This is currently its SHA-1
in hex.
@@ -144,7 +166,7 @@ class IP4AddressMonitor(gobject.GObject):
sys_bus = dbus.SystemBus()
proxy = sys_bus.get_object(NM_SERVICE, NM_PATH)
self._nm_obj = dbus.Interface(proxy, NM_IFACE)
- except dbus.DBusException, err:
+ except DBusException, err:
_logger.debug("Error finding NetworkManager: %s" % err)
self._nm_present = False
return