diff --git a/sugar/Makefile.am b/sugar/Makefile.am index f683cc8a..6f27a08d 100644 --- a/sugar/Makefile.am +++ b/sugar/Makefile.am @@ -7,7 +7,6 @@ sugar_PYTHON = \ env.py \ logger.py \ setup.py \ - oldsimulator.py \ simulator.py \ TracebackUtils.py \ util.py diff --git a/sugar/oldsimulator.py b/sugar/oldsimulator.py deleted file mode 100644 index 271d5ed5..00000000 --- a/sugar/oldsimulator.py +++ /dev/null @@ -1,108 +0,0 @@ -import os - -import gtk -import gobject -import base64 -import dbus - -from sugar.session.TestSession import TestSession -from sugar.presence import PresenceService -from sugar.p2p import Stream -from sugar import util - -_PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp" - -class _SimulatedActivity: - def __init__(self): - self._id = util.unique_id() - - def get_id(self): - return self._id - -class _SimulatedShellOwner(object): - def __init__(self, nick, color, icon_file=None): - self._pservice = PresenceService.get_instance() - self._color = color - self._nick = nick - - self._icon = None - if icon_file: - fd = open(icon_file, "r") - self._icon = fd.read() - fd.close() - - def announce(self): - props = { 'color': self._color.to_string() } - self._service = self._pservice.register_service(self._nick, - _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._icon: - 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 _Timeline: - def __init__(self, time_factor): - self._time_factor = time_factor - - def add(self, action, minutes): - gobject.timeout_add(int(1000 * 60 * minutes * self._time_factor), - self._execute_action_cb, action) - - def _execute_action_cb(self, action): - action.execute() - return False - -class ShareActivityAction: - def __init__(self, title, activity_type, callback=None): - self._title = title - self._type = activity_type - self._callback = callback - - def execute(self): - activity = _SimulatedActivity() - properties = { 'title' : self._title } - - pservice = PresenceService.get_instance() - act_service = pservice.share_activity(activity, self._type, properties) - if self._callback is not None: - self._callback(activity, act_service) - -class Bot: - def __init__(self, nick, color): - self._nick = nick - self._color = color - self._timeline = _Timeline(0.01) - self._owner = None - self._icon_file = None - - os.environ['SUGAR_NICK_NAME'] = nick - os.environ['SUGAR_COLOR'] = color.to_string() - - def start(self): - session = TestSession() - session.start() - - PresenceService.start() - - self._owner = _SimulatedShellOwner(self._nick, self._color, self._icon_file) - self._owner.announce() - - self._pservice = PresenceService.get_instance() - - try: - gtk.main() - except KeyboardInterrupt: - pass - - def add_action(self, action, minutes): - self._timeline.add(action, minutes) diff --git a/tests/simulator/demo/kiu.py b/tests/simulator/demo/kiu.py deleted file mode 100755 index 2e8c448f..00000000 --- a/tests/simulator/demo/kiu.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/python - -from sugar.oldsimulator import Bot -from sugar.oldsimulator import ShareActivityAction -from sugar.graphics.iconcolor import IconColor -import os, random, gobject - -class KiuBot(Bot): - def __init__(self): - Bot.__init__(self, 'kiu', IconColor('#5E4505,#0F8A0F')) - self._olpc_chat_service = None - self._web_activity_service = None - self._activity_switch_timeout = None - self._curact = None - - action = ShareActivityAction('OLPC channel', - '_GroupChatActivity_Sugar_redhat_com._udp', - self.__share_olpc_chat_cb) - self.add_action(action, 10) - - action = ShareActivityAction('All About Giraffes', - '_BrowserActivity_Sugar_redhat_com._udp', - self.__share_web_activity_cb) - self.add_action(action, 20) - - curdir = os.path.abspath(os.path.dirname(__file__)) - self._icon_file = os.path.join(curdir, '../data/kiu.jpg') - - def __activity_switch_cb(self): - self._activity_switch_timeout = None - which = random.randint(1, 2) - if which == 1: - actid = self._olpc_chat_activity.get_id() - elif which == 2: - actid = self._web_activity.get_id() - else: - raise RuntimeError("WTF? unexpected value") - if actid != self._curact: - print "KIU: now setting current activity to %s" % actid - self._owner.set_current_activity(actid) - self._curact = actid - self._schedule_activity_switch_timeout() - return False - - def _schedule_activity_switch_timeout(self): - if self._activity_switch_timeout: - return - interval = random.randint(10000, 20000) - self._activity_switch_timeout = gobject.timeout_add(interval, - self.__activity_switch_cb) - - def __share_olpc_chat_cb(self, sim_activity, service): - self._olpc_chat_service = service - self._olpc_chat_activity = sim_activity - self._schedule_activity_switch_timeout() - - def __share_web_activity_cb(self, sim_activity, service): - self._web_activity_service = service - self._web_activity = sim_activity - self._schedule_activity_switch_timeout() - -def main(): - bot = KiuBot() - bot.start() - - -if __name__ == "__main__": - main() diff --git a/tests/simulator/simulator b/tests/simulator/simulator index 552512c6..9faae83a 100755 --- a/tests/simulator/simulator +++ b/tests/simulator/simulator @@ -15,7 +15,7 @@ base_path = os.path.abspath(os.path.dirname(__file__)) stage_path = os.path.join(base_path, 'demo') for bot_file in os.listdir(stage_path): - if bot_file.endswith('.py') and bot_file != 'kiu.py': + if bot_file.endswith('.py'): execfile(os.path.join(stage_path, bot_file)) mainloop = gobject.MainLoop()