Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/engine.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorius/engine.py')
-rw-r--r--tutorius/engine.py48
1 files changed, 17 insertions, 31 deletions
diff --git a/tutorius/engine.py b/tutorius/engine.py
index 34616f6..46e1152 100644
--- a/tutorius/engine.py
+++ b/tutorius/engine.py
@@ -31,12 +31,12 @@ STOP_MSG_PRIORITY = 5
EVENT_NOTIFICATION_MSG_PRIORITY = 10
# List of runner states
-RUNNER_STATE_IDLE = 0
-RUNNER_STATE_SETUP_ACTIONS = 1
-RUNNER_STATE_SETUP_EVENTS = 2
-RUNNER_STATE_AWAITING_NOTIFICATIONS = 3
-RUNNER_STATE_UNINSTALLING_ACTIONS = 4
-RUNNER_STATE_UNSUBSCRIBING_EVENTS = 5
+RUNNER_STATE_IDLE = "idle"
+RUNNER_STATE_SETUP_ACTIONS = "setup_actions"
+RUNNER_STATE_SETUP_EVENTS = "setup_events"
+RUNNER_STATE_AWAITING_NOTIFICATIONS = "awaiting_notification"
+RUNNER_STATE_UNINSTALLING_ACTIONS = "uninstalling_actions"
+RUNNER_STATE_UNSUBSCRIBING_EVENTS = "unsubscribing_events"
LOGGER = logging.getLogger("sugar.tutorius.engine")
@@ -67,7 +67,6 @@ class TutorialRunner(object):
self._state = None
#Cached objects
- self._actions = {}
self._installed_actions = {}
self._installation_errors = {}
@@ -93,9 +92,9 @@ class TutorialRunner(object):
self._runner_state == RUNNER_STATE_SETUP_EVENTS:
heappush(self._message_queue, (STOP_MSG_PRIORITY, None))
else:
- self._execute_stop()
+ self._execute_stop()
- def action_installed(self, action_name, action, address):
+ def action_installed(self, action_name, address):
LOGGER.debug("TutorialRunner :: Action %s received address %s"%(action_name, address))
self._installed_actions[action_name] = address
# Verify if we just completed the installation of the actions for this state
@@ -151,20 +150,11 @@ class TutorialRunner(object):
self._runner_state = RUNNER_STATE_AWAITING_NOTIFICATIONS
self._process_pending_messages()
- def _uninstall_actions(self):
- self._runner_state = RUNNER_STATE_UNINSTALLING_ACTIONS
- self._remove_installed_actions()
- self._execute_stop()
-
- def _unsubscribe_events(self):
- self._runner_state = RUNNER_STATE_UNSUBSCRIBING_EVENTS
- self._remove_subscribed_events()
- self._uninstall_actions()
-
###########################################################################
# Helper functions
def _execute_stop(self):
self.setCurrentActivity() #Temp Hack until activity in events/actions
+ self._teardownState()
self._state = None
self._runner_state = RUNNER_STATE_IDLE
@@ -176,6 +166,7 @@ class TutorialRunner(object):
for (this_event, this_next_state_name) in transitions.values():
if event == this_event and next_state == this_next_state_name:
self.enterState(next_state)
+ break
elif self._runner_state == RUNNER_STATE_SETUP_EVENTS:
LOGGER.debug("TutorialRunner :: Queuing event notification to go to state %s"%next_state)
# Push the message on the queue
@@ -194,7 +185,6 @@ class TutorialRunner(object):
for (action_name, action_address) in self._installed_actions.items():
LOGGER.debug("TutorialRunner :: Uninstalling action %s with address %s"%(action_name, action_address))
self._pM.uninstall(action_address)
- self._actions = {}
self._installed_actions.clear()
self._installation_errors.clear()
@@ -206,10 +196,12 @@ class TutorialRunner(object):
self._subscription_errors.clear()
def _verify_action_install_state(self):
+ actions = self._tutorial.get_action_dict(self._state)
+
# Do the check to see if we have finished installing all the actions by either having
# received a address for it or an error message
install_complete = True
- for (this_action_name, this_action) in self._actions.items():
+ for (this_action_name, this_action) in actions.items():
if not this_action_name in self._installed_actions.keys() and \
not this_action_name in self._installation_errors.keys():
# There's at least one uninstalled action, so we still wait
@@ -244,13 +236,7 @@ class TutorialRunner(object):
LOGGER.debug("TutorialRunner :: Stop message taken from message queue")
# We can safely ignore the rest of the events
self._message_queue = []
- #self._execute_stop()
- # Start removing the installed addons
- if self._runner_state == RUNNER_STATE_AWAITING_NOTIFICATIONS:
- # Start uninstalling the events
- self._unsubscribe_events()
- if self._runner_state == RUNNER_STATE_SETUP_EVENTS:
- self._uninstall_actions()
+ self._execute_stop()
elif priority == EVENT_NOTIFICATION_MSG_PRIORITY:
LOGGER.debug("TutorialRunner :: Handling stored event notification for next_state %s"%message[0])
self._handle_event(*message)
@@ -259,13 +245,13 @@ class TutorialRunner(object):
if self._state is None:
raise RuntimeError("Attempting to setupState without a state")
- self._actions = self._tutorial.get_action_dict(self._state)
+ actions = self._tutorial.get_action_dict(self._state)
- if len(self._actions) == 0:
+ if len(actions) == 0:
self.all_actions_installed()
return
- for (action_name, action) in self._actions.items():
+ for (action_name, action) in actions.items():
LOGGER.debug("TutorialRunner :: Installed action %s"%(action_name))
self._pM.install(action,
save_args(self.action_installed, action_name),