Exemplo n.º 1
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 jarbas_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

    # 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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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, {})
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def __init__(self, name):
     self.name = name.lower()
     self.config = read_mycroft_config().get(self.name, {})
     self.intent_samples = {}
     self.entity_samples = {}
     self.regex_samples = {}