Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tutorius/engine.py
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-11-22 04:24:14 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-11-22 04:24:14 (GMT)
commit00c4fe9e5f2373fcefe6fb3f46e641a3c416423e (patch)
tree7e9dadd6322fe3fde25de423ab71aefde1a55c19 /tutorius/engine.py
parent79349369000d53741a8874929044af4b6b48f2f4 (diff)
LP 448319 : Moving action installation to asynchronous version with confirmation
Diffstat (limited to 'tutorius/engine.py')
-rw-r--r--tutorius/engine.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/tutorius/engine.py b/tutorius/engine.py
index 10c8d14..bb2453a 100644
--- a/tutorius/engine.py
+++ b/tutorius/engine.py
@@ -30,6 +30,7 @@ class TutorialRunner(object):
#Cached objects
self._actions = {}
self._installed_actions = {}
+ self._install_errors = {}
#Temp FIX until event/actions have an activity id
self._activity_id = None
@@ -62,17 +63,45 @@ class TutorialRunner(object):
LOGGER.debug("TutorialRunner :: Uninstalling action %s with address %s"%(action_name, action_address))
self._pM.uninstall(action_address)
self._actions = {}
- self._installed_actions = {}
+ self._installed_actions.clear()
+ self._install_errors.clear()
#Clear the EventFilters
for event in self._sEvents:
self._pM.unsubscribe(event)
self._sEvents.clear()
- def __action_installed(self, action_name, address):
+ def __action_installed(self, action_name, action, address):
LOGGER.debug("TutorialRunner :: Action %s received address %s"%(action_name, address))
self._installed_actions[action_name] = address
+ # 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():
+ if not this_action_name in self._installed_actions.keys() and not this_action in self._install_errors.keys():
+ # There's at least one uninstalled action, so we still wait
+ install_complete = False
+ break
+
+ if install_complete:
+ LOGGER.debug("TutorialRunner :: All actions installed!")
+ # Raise the All Actions Installed event for the TutorialRunner state
+ self._all_actions_installed()
+
+ def __install_error(self, action_name, action, exception):
+ # TODO : Fix this as it doesn't warn the user about the problem or anything
+ LOGGER.debug("TutorialRunner :: Action could not be installed %s, exception was : %s"%(str(action) + str(exception)))
+ self._install_errors[action_name] = exception
+
+ def _all_actions_installed(self):
+ transitions = self._tutorial.get_transition_dict(self._state)
+
+ if len(transitions) == 0:
+ return
+ for (event, next_state) in transitions.values():
+ self._sEvents.add(self._pM.subscribe(event, save_args(self._handleEvent, next_state)))
+
def _setupState(self):
if self._state is None:
raise RuntimeError("Attempting to setupState without a state")
@@ -88,13 +117,15 @@ class TutorialRunner(object):
state_name = next_state
return state_name
+ if len(self._actions) == 0:
+ self._all_actions_installed()
+ return state_name
+
for (action_name, action) in self._actions.items():
- self._pM.install(action, save_args(self.__action_installed, action_name), True)
+ self._pM.install(action, save_args(self.__action_installed, action_name),
+ save_args(self.__install_error, action_name))
LOGGER.debug("TutorialRunner :: Installed action %s"%(action_name))
-
- for (event, next_state) in transitions.values():
- self._sEvents.add(self._pM.subscribe(event, save_args(self._handleEvent, next_state)))
-
+
return state_name
def enterState(self, state_name):