def test_engine_google_init(self):

        a_config = audio_handler.AudioHandlerConfigModel()
        a_config.speech_engine = audio_handler.SPEECH_ENGINE_GOOGLE
        a_handler = audio_handler.AudioHandler(p_config=a_config)

        self.assertIsNotNone(a_handler)
    def test_engine_invalid(self):

        a_config = audio_handler.AudioHandlerConfigModel()
        a_config.speech_engine = "NOT-EXISTING"

        with self.assertRaises(configuration.ConfigurationException):
            a_handler = audio_handler.AudioHandler(p_config=a_config)
            self.assertIsNotNone(a_handler)
    def test_engine_external_init(self):

        a_config = audio_handler.AudioHandlerConfigModel()
        a_config.speech_engine = audio_handler.SPEECH_ENGINE_EXTERNAL
        a_handler = audio_handler.AudioHandler(p_config=a_config)

        self.assertIsNotNone(a_handler)

        a_handler.stop_engine()
    def test_engine_external_speak(self):

        a_config = audio_handler.AudioHandlerConfigModel()
        a_config.speech_engine = audio_handler.SPEECH_ENGINE_EXTERNAL
        a_config.spool_dir = SPOOL_DIR
        a_handler = audio_handler.AudioHandler(p_config=a_config)

        self.assertIsNotNone(a_handler)

        self.delete_audio_file(p_audio_handler=a_handler)
        a_handler.notify(p_text=TEXT)

        a_handler.stop_engine()
    def test_engine_google_speak(self):

        a_config = audio_handler.AudioHandlerConfigModel()
        a_config.speech_engine = audio_handler.SPEECH_ENGINE_GOOGLE
        a_config.spool_dir = SPOOL_DIR
        a_config.locale = LOCALE
        a_handler = audio_handler.AudioHandler(p_config=a_config)

        self.assertIsNotNone(a_handler)

        self.delete_audio_file(p_audio_handler=a_handler)
        a_handler.notify(p_text=TEXT, p_locale=LOCALE)
        a_handler.notify(p_text=TEXT, p_locale=LOCALE)
        a_handler.stop_engine()
    def test_spool_dir_and_file(self):

        a_config = audio_handler.AudioHandlerConfigModel()
        a_config.speech_engine = audio_handler.SPEECH_ENGINE_GOOGLE
        a_config.spool_dir = SPOOL_DIR
        a_handler = audio_handler.AudioHandler(p_config=a_config)

        self.assertIsNotNone(a_handler)

        audio_file = a_handler.get_audio_filename(p_text=TEXT, p_locale=None)

        self.assertTrue(audio_file.startswith(SPOOL_DIR))

        self.delete_audio_file(p_audio_handler=a_handler)
        a_thread = a_handler.notify(p_text=TEXT)
        a_thread.join()
        #        time.sleep(1)

        self.assertTrue(os.path.exists(audio_file))

        a_handler.stop_engine()
Exemple #7
0
    def prepare_services(self, p_full_startup=True):

        super().prepare_services(p_full_startup=p_full_startup)

        # TODO: Activate in memory sqlite backend for slaves
        self._persistence = persistence.Persistence(
            p_config=self._config[persistence.SECTION_NAME])

        if not p_full_startup:
            return

        if self.is_master():
            self._rule_handler = rule_handler.RuleHandler(
                p_config=self._config[rule_handler.SECTION_NAME],
                p_persistence=self._persistence)

        self._master_connector = master_connector.MasterConnector(
            p_config=self._config[master_connector.SECTION_NAME])

        config = self._config[audio_handler.SECTION_NAME]

        if config.is_active():
            self._notification_handlers.append(
                audio_handler.AudioHandler(p_config=config))

        config = self._config[popup_handler.SECTION_NAME]

        if config.is_active():
            self._notification_handlers.append(
                popup_handler.PopupHandler(p_config=config))

        self.check_migrations()

        process_handler = client_process_handler.ClientProcessHandler(
            p_config=self._config[client_process_handler.SECTION_NAME],
            p_process_iterator_factory=ProcessIteratorFactory())

        self._client_device_handler = client_device_handler.ClientDeviceHandler(
            p_config=self._config[client_device_handler.SECTION_NAME],
            p_persistence=self._persistence)

        self._process_handlers = {
            process_handler.id: process_handler,
            self._client_device_handler.id: self._client_device_handler
        }

        config = self._config[prometheus.SECTION_NAME]

        if config.is_active():
            self._prometheus_client = prometheus.PrometheusClient(
                p_logger=self._logger, p_config=config)

        unix_user_handler_config = self._config[unix_user_handler.SECTION_NAME]
        status_server_config = self._config[status_server.SECTION_NAME]

        self.init_babel(p_localeselector=self.get_request_locale)

        localedir = os.path.join(os.path.dirname(__file__), "translations")
        a_locale_helper = locale_helper.LocaleHelper(
            p_locale_selector=self.get_request_locale, p_locale_dir=localedir)
        self.add_locale_helper(a_locale_helper)

        if self.is_master():
            if status_server_config.is_active():
                if status_server_config.admin_password is not None:
                    msg = "admin_user and admin_password in section [StatusSever] " \
                          "should be moved to section [UnixUserHandler]"
                    self._logger.warning(msg)

                    if not unix_user_handler_config.is_active():
                        unix_user_handler_config.admin_username = status_server_config.admin_username
                        unix_user_handler_config.admin_password = status_server_config.admin_password

                if self.is_master(
                ) and not unix_user_handler_config.is_active():
                    msg = "admin_user and admin_password must be supplied in section [UnixUserHandler]"
                    raise configuration.ConfigurationException(msg)

                if unix_user_handler_config.is_active():
                    self._user_handler = unix_user_handler.UnixUserHandler(
                        p_config=unix_user_handler_config,
                        p_exclude_user_list=[constants.APPLICATION_USER])

        else:
            self._user_handler = unix_user_handler.UnixUserHandler(
                p_config=unix_user_handler_config)

        self._login_mapping = login_mapping.LoginMapping()
        self._login_mapping.read_from_configuration(
            p_login_mapping_section_handler=self._login_mapping_section_handler
        )

        self._app_control = app_control.AppControl(
            p_config=self._config[app_control.SECTION_NAME],
            p_debug_mode=self._app_config.debug_mode,
            p_process_handlers=self._process_handlers,
            p_device_handler=self._client_device_handler,
            p_persistence=self._persistence,
            p_rule_handler=self._rule_handler,
            p_notification_handlers=self._notification_handlers,
            p_master_connector=self._master_connector,
            p_prometheus_client=self._prometheus_client,
            p_user_handler=self._user_handler,
            p_locale_helper=self.locale_helper,
            p_login_mapping=self._login_mapping)

        if self._config[app_control.SECTION_NAME].scan_active:
            task = base_app.RecurringTask(
                p_name="app_control.scan_processes(ProcessHandler)",
                p_handler_method=lambda: self._app_control.scan_processes(
                    p_process_handler=process_handler),
                p_interval=process_handler.check_interval)
            self.add_recurring_task(p_recurring_task=task)

        else:
            fmt = "Process scanning for this host has been deactivated in configuration"
            self._logger.warning(fmt)

        if self._client_device_handler:
            task = base_app.RecurringTask(
                p_name="app_control.scan_processes(DeviceHandler)",
                p_handler_method=lambda: self._app_control.scan_processes(
                    p_process_handler=self._client_device_handler),
                p_interval=self._client_device_handler.check_interval)
            self.add_recurring_task(p_recurring_task=task)

        if status_server_config.is_active():
            self._status_server = status_server.StatusServer(
                p_config=self._config[status_server.SECTION_NAME],
                p_package_name=PACKAGE_NAME,
                p_app_control=self._app_control,
                p_master_connector=self._master_connector,
                p_persistence=self._persistence,
                p_is_master=self.is_master(),
                p_locale_helper=self._locale_helper,
                p_base_gettext=self.gettext,
                p_languages=constants.LANGUAGES,
                p_user_handler=self._user_handler)

        elif self.is_master():
            msg = "Master instance requires port number for web server"
            raise configuration.ConfigurationException(msg)

        else:
            msg = "Slave instance will not start web server due to missing port number"
            self._logger.warn(msg)

        task = base_app.RecurringTask(
            p_name="app_control.check",
            p_handler_method=self._app_control.check,
            p_interval=self._app_control.check_interval)
        self.add_recurring_task(p_recurring_task=task)