Exemplo n.º 1
0
 def test_write_github_token(self):
     config_path = os.path.join(ROOT_DIR, "configuration")
     token = "TOKEN"
     local_config = get_neon_local_config(config_path)
     self.assertIsNone(local_config["skills"]["neon_token"])
     populate_github_token_config(token, config_path)
     self.assertEqual(local_config["skills"]["neon_token"], token)
Exemplo n.º 2
0
    def __init__(self, name=None, bus=None, use_settings=True):
        self.user_config = get_neon_user_config()
        self.local_config = get_neon_local_config()

        self._ngi_settings: Optional[NGIConfig] = None

        super(NeonSkill, self).__init__(name, bus, use_settings)
        self.cache_loc = os.path.expanduser(self.local_config.get('dirVars', {}).get('cacheDir') or
                                            "~/.local/share/neon/cache")
        self.lru_cache = LRUCache()

        # TODO: Depreciate these references, signal use is discouraged DM
        self.create_signal = create_signal
        self.check_for_signal = check_for_signal

        self.sys_tz = gettz()
        self.gui_enabled = self.local_config.get("prefFlags", {}).get("guiEvents", False)

        # if use_settings:
        #     self.settings = {}
        #     self._initial_settings = None
        #     self.init_settings()
        # else:
        #     LOG.error(f"{name} Skill requested no settings!")
        #     self.settings = None

        self.scheduled_repeats = []

        # Server-specific imports and timeout setting
        # A server is a device that hosts the core and skills to serve clients,
        # but that a user will not interact with directly.
        # A server will likely serve multiple users and devices concurrently.
        if self.local_config.get("devVars", {}).get("devType", "generic") == "server":
            self.server = True
            self.default_intent_timeout = 90
        else:
            self.server = False
            self.default_intent_timeout = 60

        self.neon_core = True  # TODO: This should be depreciated DM
        self.actions_to_confirm = dict()

        self.skill_mode = self.user_config.content.get('response_mode', {}).get('speed_mode') or DEFAULT_SPEED_MODE
        self.extension_time = SPEED_MODE_EXTENSION_TIME.get(self.skill_mode)

        try:
            # Lang support
            self.language_config = get_neon_lang_config()
            self.lang_detector = DetectorFactory.create()  # Default fastlang
            self.translator = TranslatorFactory.create()  # Default Amazon
        except Exception as e:
            LOG.error(e)
            self.language_config, self.language_detector, self.translator = None, None, None
Exemplo n.º 3
0
 def test_get_speech_module_config(self):
     from neon_speech.utils import get_speech_module_config
     config = get_speech_module_config()
     self.assertIsInstance(config, dict)
     self.assertIsInstance(config["stt"], dict)
     self.assertIsInstance(config["listener"], dict)
     local_config = get_neon_local_config()
     local_config["stt"]["module"] = "test_mod"
     local_config.write_changes()
     new_config = get_speech_module_config()
     self.assertNotEqual(config, new_config)
     self.assertEqual(new_config["stt"]["module"], "test_mod")
Exemplo n.º 4
0
 def test_write_aws_credentials(self):
     config_path = os.path.join(ROOT_DIR, "configuration")
     local_config = get_neon_local_config(config_path)
     self.assertEqual(
         local_config["tts"]["amazon"], {
             "region": "us-west-2",
             "aws_access_key_id": "",
             "aws_secret_access_key": ""
         })
     populate_amazon_keys_config(
         {
             "aws_access_key_id": "KEY_ID",
             "aws_secret_access_key": "KEY_SECRET"
         }, config_path)
     self.assertEqual(
         local_config["tts"]["amazon"], {
             "region": "us-west-2",
             "aws_access_key_id": "KEY_ID",
             "aws_secret_access_key": "KEY_SECRET"
         })
Exemplo n.º 5
0
# Authors: Guy Daniels, Daniel McKnight, Regina Bloomstine, Elon Gasper, Richard Leeds
#
# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp.
# US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924
# China Patent: CN102017585  -  Europe Patent: EU2156652  -  Patents Pending
import os

import logging

from datetime import datetime, timedelta
from typing import Optional, Union

from neon_utils.logger import LOG
from neon_utils.configuration_utils import get_neon_local_config

LOG_DIR = os.path.expanduser(get_neon_local_config()["dirVars"]["logsDir"])


def remove_old_logs(log_dir: str = LOG_DIR,
                    history_to_retain: timedelta = timedelta(weeks=6)):
    """
    Removes archived logs older than the specified history timedelta
    Args:
        log_dir: Path to archived logs
        history_to_retain: Timedelta of history to retain
    """
    from shutil import rmtree
    for archive in os.listdir(log_dir):
        archive_path = os.path.join(log_dir, archive)
        if not os.path.isdir(archive_path):
            continue