Пример #1
0
 def __init__(self, name, config=None):
     self.name = name.lower()
     config = config or read_mycroft_config()
     self.config = config.get(self.name, {})
     self.intent_samples = {}
     self.entity_samples = {}
     self.regex_samples = {}
Пример #2
0
def get_current_marketplace_branch():
    # TODO check mycroft version for default branch as fallback
    try:
        default_branch = read_mycroft_config().get("skills", {}) \
            .get("msm", {}).get("repo", {}).get("branch", "21.02")
    except FileNotFoundError:
        default_branch = "21.02"
    return default_branch
Пример #3
0
def blacklist_skill(skill):
    skills_config = read_mycroft_config().get("skills", {})
    blacklisted_skills = skills_config.get("blacklisted_skills", [])
    if skill not in blacklisted_skills:
        blacklisted_skills.append(skill)
        conf = {"skills": {"blacklisted_skills": blacklisted_skills}}
        update_mycroft_config(conf)
        return True
    return False
Пример #4
0
def make_priority_skill(skill):
    skills_config = read_mycroft_config().get("skills", {})
    priority_skills = skills_config.get("priority_skills", [])
    if skill not in priority_skills:
        priority_skills.append(skill)
        conf = {"skills": {"priority_skills": priority_skills}}
        update_mycroft_config(conf)
        return True
    return False
Пример #5
0
 def __init__(self, query_message, name=None, timeout=5, bus=None):
     self.query_message = query_message
     self.query_message.context["source"] = self.name
     self.name = name or self.__class__.__name__
     self.bus = bus or get_mycroft_bus()
     self.config = read_mycroft_config().get(self.name, {})
     self.timeout = timeout
     self.query = None
     self.valid_responses = []
     self._daemon = None
def _safe_mycroft_config() -> dict:
    """
    Safe reference to mycroft config that always returns a dict
    Returns:
        dict mycroft configuration
    """
    try:
        mycroft = read_mycroft_config()
    except FileNotFoundError:
        mycroft = LocalConf(os.path.join(os.path.dirname(__file__), "default_configurations", "mycroft.conf"))
    return mycroft
Пример #7
0
    def __init__(self, trigger_message, name=None, bus=None):
        """
           initialize responder

           args:
                name(str): name identifier for .conf settings
                bus (WebsocketClient): mycroft messagebus websocket
        """
        self.trigger_message = trigger_message
        self.name = name or self.__class__.__name__
        self.bus = bus or get_mycroft_bus()
        self.callback = None
        self.service = None
        self._daemon = None
        self.config = read_mycroft_config().get(self.name, {})
Пример #8
0
 def bind_engine(self, engine, priority=4):
     priority_skills = read_mycroft_config().get("skills", {}).get(
         "priority_skills", [])
     priority_skills.append(self.root_dir.split("/")[-1])
     update_mycroft_config({
         "skills":
             {"priority_skills": priority_skills}
     })
     self.priority = priority
     self.engine = engine
     self.config = engine.config
     self.register_messages(engine.name)
     self.register_fallback(self.handle_fallback, self.priority)
     self.finished_training_event = Event()
     self.finished_initial_train = False
     self.train_delay = self.engine.config.get('train_delay', 4)
     self.train_time = get_time() + self.train_delay
Пример #9
0
def get_ipc_directory(domain=None):
    """Get the directory used for Inter Process Communication

    Files in this folder can be accessed by different processes on the
    machine.  Useful for communication.  This is often a small RAM disk.

    Args:
        domain (str): The IPC domain.  Basically a subdirectory to prevent
            overlapping signal filenames.

    Returns:
        str: a path to the IPC directory
    """
    config = read_mycroft_config()
    path = config.get("ipc_path")
    if not path:
        # If not defined, use /tmp/mycroft/ipc
        path = os.path.join(tempfile.gettempdir(), "mycroft", "ipc")
    return ensure_directory_exists(path, domain)
Пример #10
0
    def __init__(self, bus=None):
        self.bus = bus or get_mycroft_bus()
        self.config = read_mycroft_config().get("common_windows") or {}
        self.service_lock = Lock()

        self.default = None
        self.services = []
        self.current = None

        raise NotImplementedError
        self.services = load_services(self.config, self.bus)

        # Register end of picture callback
        for s in self.services:
            s.set_window_start_callback(self.on_display_start)

        # Find default backend
        default_name = self.config.get('default-backend', '')
        LOG.info('Finding default backend...')
        for s in self.services:
            if s.name == default_name:
                self.default = s
                LOG.info('Found ' + self.default.name)
                break
        else:
            self.default = None
            LOG.info('no default found')

        # Setup event handlers
        self.bus.on('ovos.ccanvas.window', self._display)
        self.bus.on('ovos.ccanvas.queue', self._queue)
        self.bus.on('ovos.ccanvas.stop', self._stop)
        self.bus.on('ovos.ccanvas.clear', self._clear)
        self.bus.on('ovos.ccanvas.close', self._close)
        self.bus.on('ovos.ccanvas.reset', self._reset)
        self.bus.on('ovos.ccanvas.next', self._next)
        self.bus.on('ovos.ccanvas.prev', self._prev)
        self.bus.on('ovos.ccanvas.height', self._set_height)
        self.bus.on('ovos.ccanvas.width', self._set_width)
        self.bus.on('ovos.ccanvas.fullscreen', self._set_fullscreen)
        self.bus.on('ovos.ccanvas.picture_info', self._picture_info)
        self.bus.on('ovos.ccanvas.list_backends', self._list_backends)
def get_current_marketplace_branch():
    # TODO check mycroft version for default branch as fallback
    default_branch = read_mycroft_config().get("skills", {}) \
        .get("msm", {}).get("repo", {}).get("branch", "20.08")
    return default_branch
Пример #12
0
def get_skills_folder():
    config = read_mycroft_config()
    data_dir = config["data_dir"]
    skill_folder = config["skills"]["msm"]["directory"]
    return join(data_dir, skill_folder)
Пример #13
0
def resolve_resource_file(res_name, root_path=None):
    """Convert a resource into an absolute filename.

    Resource names are in the form: 'filename.ext'
    or 'path/filename.ext'

    The system wil look for ~/.mycroft/res_name first, and
    if not found will look at /opt/mycroft/res_name,
    then finally it will look for res_name in the 'mycroft/res'
    folder of the source code package.

    Example:
    With mycroft running as the user 'bob', if you called
        resolve_resource_file('snd/beep.wav')
    it would return either '/home/bob/.mycroft/snd/beep.wav' or
    '/opt/mycroft/snd/beep.wav' or '.../mycroft/res/snd/beep.wav',
    where the '...' is replaced by the path where the package has
    been installed.

    Args:
        res_name (str): a resource path/name
    Returns:
        str: path to resource or None if no resource found
    """
    # TODO handle cyclic import
    from ovos_utils.configuration import read_mycroft_config
    config = read_mycroft_config()

    # First look for fully qualified file (e.g. a user setting)
    if os.path.isfile(res_name):
        return res_name

    # Now look for ~/.mycroft/res_name (in user folder)
    filename = os.path.expanduser("~/.mycroft/" + res_name)
    if os.path.isfile(filename):
        return filename

    # Next look for /opt/mycroft/res/res_name
    data_dir = os.path.expanduser(config['data_dir'])
    filename = os.path.expanduser(os.path.join(data_dir, res_name))
    if os.path.isfile(filename):
        return filename

    # look in ovos_utils package itself
    found = resolve_ovos_resource_file(res_name)
    if found:
        return found

    # Finally look for it in the source package
    paths = [
        "/opt/venvs/mycroft-core/lib/python3.7/site-packages/",  # mark1/2
        "/opt/venvs/mycroft-core/lib/python3.4/site-packages/ ",  # old mark1 installs
        "/home/pi/mycroft-core"  # picroft
    ]
    if root_path:
        paths += [root_path]
    for p in paths:
        filename = os.path.join(p, 'mycroft', 'res', res_name)
        filename = os.path.abspath(os.path.normpath(filename))
        if os.path.isfile(filename):
            return filename

    return None  # Resource cannot be resolved