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.master
parent
1dd8f78453
commit
cbd3a52a68
@ -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()
|
@ -0,0 +1,6 @@
|
||||
from sugar.simulator import Bot
|
||||
|
||||
bot = Bot()
|
||||
bot.name = 'penelope'
|
||||
|
||||
bot.start()
|
@ -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()
|
Loading…
Reference in New Issue