def initialize(self, environment, except_hook): """ Initializes the simulation :param environment: The environment that should be simulated :param except_hook: A method that should be called when there is a critical error """ # Change working directory to experiment directory logger.info("Path is " + self.__exc.path) os.chdir(self.__exc.dir) # Create backend->frontend/client ROS notificator logger.info("Setting up backend Notificator") self.ros_notificator = ROSNotificator() Notificator.register_notification_function( lambda subtask, update_progress: self.ros_notificator.update_task( subtask, update_progress, True)) # Number of subtasks is not used in frontend notificator logic self.ros_notificator.start_task("Neurorobotics Platform", "Neurorobotics Platform", number_of_subtasks=1, block_ui=True) self._notify("Starting Neurorobotics Platform") self._initialize(environment, except_hook) # Loading is completed. self._notify("Finished") self.ros_notificator.finish_task() logger.info("CLELauncher Finished.")
def _notify(self, message): """ Checks whether the simulation should abort immediately """ if self._abort_initialization is not None: raise Exception("The simulation must abort due to: " + self._abort_initialization) Notificator.notify(message, True)
def start_fetching_gazebo_logs(self): """ Starts to fetch the logs from gazebo and putting them as notifications """ gazebo_logger.handlers.append(notificator_handler) Notificator.register_notification_function( lambda subtask, update_progress: self._notificator.update_task( subtask, update_progress, True))
def test_notificator_handler(self): messages = [] def notify_handler(message, update_progress): messages.append(message) Notificator.register_notification_function(notify_handler) logger = logging.getLogger("TestLogger") logger.addHandler(NotificatorHandler()) logger.setLevel(logging.INFO) logger.info("Foo") logger.info("%s", "Bar") logger.debug("Debug") self.assertEqual(2, len(messages)) self.assertEqual("Foo", messages[0]) self.assertEqual("Bar", messages[1])
def initialize(self, except_hook): """ Initializes the simulation :param environment: The environment that should be simulated :param except_hook: A method that should be called when there is a critical error """ # Change working directory to experiment directory logger.info("Path is " + self._sim_config.sim_dir) os.chdir(self._sim_config.sim_dir) # RNG seed for components, use config value if specified or generate a new one self.rng_seed = self.sim_config.rng_seed if self.rng_seed is None: logger.info( 'No RNG seed specified in the exc, using random value.') self.rng_seed = random.randint(1, sys.maxint) logger.info('RNG seed = %i', self.rng_seed) # Create backend->frontend/client ROS notificator logger.info("Setting up backend Notificator") self.ros_notificator = ROSNotificator() Notificator.register_notification_function( lambda subtask, update_progress: self.ros_notificator.update_task( subtask, update_progress, True)) # Number of subtasks is not used in frontend notificator logic self.ros_notificator.start_task("Neurorobotics Platform", "Neurorobotics Platform", number_of_subtasks=1, block_ui=True) self._notify("Starting Neurorobotics Platform") self._initialize(except_hook) # Loading is completed. self._notify("Finished") self.ros_notificator.finish_task() logger.info("CLELauncher Finished.")
def test_notificator(self): notify = MagicMock() Notificator.register_notification_function(notify) Notificator.notify('test_message', 'test_update') self.assertEqual(notify.call_count, 1)