From 55a0596c92c33f7aa4763affaa097efdcf33cd3c Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 22 Nov 2009 04:24:14 +0000 Subject: LP 448319 : Moving action installation to asynchronous version with confirmation --- (limited to 'tutorius/engine.py') 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): -- cgit v0.9.1