Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-10-09 13:11:15 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-10-09 13:11:15 (GMT)
commitcbd3a52a6852574e3f481dac0ff2fc51c8d5038d (patch)
treed23c947525502e83be7b7640f21ed17eb276ace9
parent1dd8f784535920dc1eb404b491761f442590e68c (diff)
Do not set up the owner of the presence service if there
is no nick name in the env. I'm not sure this is the best approach, we need to figure it out. First go at the new simulator.
-rw-r--r--services/presence/PresenceService.py11
-rw-r--r--sugar/Makefile.am1
-rw-r--r--sugar/env.py10
-rw-r--r--sugar/simulator.py47
-rw-r--r--tests/simulator/bots/penelope.py6
-rwxr-xr-xtests/simulator/simulator22
6 files changed, 92 insertions, 5 deletions
diff --git a/services/presence/PresenceService.py b/services/presence/PresenceService.py
index 71fd641..d3f0ea5 100644
--- a/services/presence/PresenceService.py
+++ b/services/presence/PresenceService.py
@@ -5,6 +5,7 @@ import Activity
import random
import logging
from sugar import util
+from sugar import env
import BuddyIconCache
@@ -302,9 +303,13 @@ class PresenceService(object):
self._icon_cache = BuddyIconCache.BuddyIconCache()
# Our owner object
- objid = self._get_next_object_id()
- self._owner = Buddy.Owner(self, self._bus_name, objid, self._icon_cache)
- self._buddies[self._owner.get_name()] = self._owner
+ if env.get_nick_name():
+ objid = self._get_next_object_id()
+ self._owner = Buddy.Owner(self, self._bus_name,
+ objid, self._icon_cache)
+ self._buddies[self._owner.get_name()] = self._owner
+ else:
+ self._owner = None
self._started = False
diff --git a/sugar/Makefile.am b/sugar/Makefile.am
index d45f1f6..f683cc8 100644
--- a/sugar/Makefile.am
+++ b/sugar/Makefile.am
@@ -8,6 +8,7 @@ sugar_PYTHON = \
logger.py \
setup.py \
oldsimulator.py \
+ simulator.py \
TracebackUtils.py \
util.py
diff --git a/sugar/env.py b/sugar/env.py
index b0c5443..036d944 100644
--- a/sugar/env.py
+++ b/sugar/env.py
@@ -14,10 +14,16 @@ def setup_user(profile):
os.environ['SUGAR_COLOR'] = profile.get_color().to_string()
def get_nick_name():
- return os.environ['SUGAR_NICK_NAME']
+ if os.environ.has_key('SUGAR_NICK_NAME'):
+ return os.environ['SUGAR_NICK_NAME']
+ else:
+ return None
def get_color():
- return os.environ['SUGAR_COLOR']
+ if os.environ.has_key('SUGAR_COLOR'):
+ return os.environ['SUGAR_COLOR']
+ else:
+ return None
def setup_python_path():
for path in sugar_python_path:
diff --git a/sugar/simulator.py b/sugar/simulator.py
new file mode 100644
index 0000000..c7fccfa
--- /dev/null
+++ b/sugar/simulator.py
@@ -0,0 +1,47 @@
+from sugar.presence import PresenceService
+from sugar.graphics.iconcolor import IconColor
+from sugar.p2p import Stream
+from sugar import util
+
+_PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
+
+class BotService(object):
+ def __init__(self, bot):
+ self._bot = bot
+
+ def announce(self):
+ props = { 'color': self._bot.color.to_string() }
+ pservice = PresenceService.get_instance()
+ self._service = pservice.register_service(self._bot.name,
+ _PRESENCE_SERVICE_TYPE, properties=props)
+
+ self._stream = Stream.Stream.new_from_service(self._service)
+ self._stream.register_reader_handler(
+ self._handle_buddy_icon_request, "get_buddy_icon")
+ self._stream.register_reader_handler(
+ self._handle_invite, "invite")
+
+ def _handle_buddy_icon_request(self):
+ if self._bot.icon:
+ fd = open(self._bot.icon, "r")
+ icon_data = fd.read()
+ fd.close()
+ if icon_data:
+ return base64.b64encode(self._icon)
+ return ''
+
+ def _handle_invite(self, issuer, bundle_id, activity_id):
+ return ''
+
+ def set_current_activity(self, activity_id):
+ self._service.set_published_value('curact', dbus.String(activity_id))
+
+class Bot(object):
+ def __init__(self):
+ self.name = util.unique_id()
+ self.color = IconColor()
+ self.icon = None
+
+ def start(self):
+ self._service = BotService(self)
+ self._service.announce()
diff --git a/tests/simulator/bots/penelope.py b/tests/simulator/bots/penelope.py
new file mode 100644
index 0000000..30774ae
--- /dev/null
+++ b/tests/simulator/bots/penelope.py
@@ -0,0 +1,6 @@
+from sugar.simulator import Bot
+
+bot = Bot()
+bot.name = 'penelope'
+
+bot.start()
diff --git a/tests/simulator/simulator b/tests/simulator/simulator
new file mode 100755
index 0000000..de21697
--- /dev/null
+++ b/tests/simulator/simulator
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+import os
+
+import gobject
+
+from sugar.session.TestSession import TestSession
+from sugar.presence import PresenceService
+
+session = TestSession()
+session.start()
+
+PresenceService.start()
+
+base_path = os.path.abspath(os.path.dirname(__file__))
+
+bots_path = os.path.join(base_path, 'bots')
+for bot_file in os.listdir(bots_path):
+ if bot_file.endswith('.py') and bot_file != 'kiu.py':
+ execfile(os.path.join(bots_path, bot_file))
+
+mainloop = gobject.MainLoop()
+mainloop.run()