diff --git a/mycroft/configuration/config.py b/mycroft/configuration/config.py index a0a645ef8c..8ffcc7bfdb 100644 --- a/mycroft/configuration/config.py +++ b/mycroft/configuration/config.py @@ -149,7 +149,7 @@ class RemoteConf(LocalConf): def __init__(self, cache=None): super(RemoteConf, self).__init__(None) - cache = cache or '/opt/mycroft/web_config_cache.json' + cache = cache or '/var/tmp/mycroft_web_cache.json' from mycroft.api import is_paired if not is_paired(): self.load_local(cache) diff --git a/mycroft/configuration/mycroft.conf b/mycroft/configuration/mycroft.conf index ddec2be9d1..cd401a3afa 100644 --- a/mycroft/configuration/mycroft.conf +++ b/mycroft/configuration/mycroft.conf @@ -83,14 +83,17 @@ "offset": -21600000 } }, + "data_dir": "/opt/mycroft", // General skill values "skills": { "msm": { - "directory": "/opt/mycroft/skills", + // Relative to "data_dir" + "directory": "skills", "versioned": true, "repo": { - "cache": "/opt/mycroft/.skills-repo", + // Relative to "data_dir" + "cache": ".skills-repo", "url": "https://github.com/MycroftAI/mycroft-skills", "branch": "18.02" } diff --git a/mycroft/skills/event_scheduler.py b/mycroft/skills/event_scheduler.py index 737e7d3894..6f3b2ebaa5 100644 --- a/mycroft/skills/event_scheduler.py +++ b/mycroft/skills/event_scheduler.py @@ -16,8 +16,9 @@ import json import time from threading import Thread -from os.path import isfile +from os.path import isfile, join +from mycroft.configuration import Configuration from mycroft.messagebus.message import Message from mycroft.util.log import LOG from queue import Queue @@ -41,7 +42,7 @@ def repeat_time(sched_time, repeat): class EventScheduler(Thread): - def __init__(self, emitter, schedule_file='/opt/mycroft/schedule.json'): + def __init__(self, emitter, schedule_file='schedule.json'): """ Create an event scheduler thread. Will send messages at a predetermined time to the registered targets. @@ -51,10 +52,12 @@ class EventScheduler(Thread): schedule_file: File to store pending events to on shutdown """ super(EventScheduler, self).__init__() + data_dir = Configuration.get()['data_dir'] + self.events = {} self.emitter = emitter self.isRunning = True - self.schedule_file = schedule_file + self.schedule_file = join(data_dir, schedule_file) if self.schedule_file: self.load() @@ -81,7 +84,7 @@ class EventScheduler(Thread): try: json_data = json.load(f) except Exception as e: - LOG.error(e.message) + LOG.error(e) current_time = time.time() for key in json_data: event_list = json_data[key] diff --git a/mycroft/skills/main.py b/mycroft/skills/main.py index c93a5ef851..0f94558dff 100644 --- a/mycroft/skills/main.py +++ b/mycroft/skills/main.py @@ -229,11 +229,13 @@ class SkillManager(Thread): config = Configuration.get() msm_config = config['skills']['msm'] repo_config = msm_config['repo'] + skills_dir = join(config['data_dir'], msm_config['directory']) + repo_cache = join(config['data_dir'], repo_config['cache']) platform = config['enclosure'].get('platform', 'default') return MycroftSkillsManager( - platform=platform, skills_dir=msm_config['directory'], + platform=platform, skills_dir=skills_dir, repo=SkillRepo( - repo_config['cache'], repo_config['url'], repo_config['branch'] + repo_cache, repo_config['url'], repo_config['branch'] ), versioned=msm_config['versioned'] ) diff --git a/mycroft/tts/mimic_tts.py b/mycroft/tts/mimic_tts.py index dbe5c8e868..c9d75bb46f 100644 --- a/mycroft/tts/mimic_tts.py +++ b/mycroft/tts/mimic_tts.py @@ -19,7 +19,7 @@ from threading import Thread from time import time, sleep import os.path -from os.path import exists +from os.path import exists, join from mycroft import MYCROFT_ROOT_PATH from mycroft.api import DeviceApi @@ -29,6 +29,7 @@ from mycroft.util.download import download from mycroft.util.log import LOG config = Configuration.get().get("tts").get("mimic") +data_dir = Configuration.get()['data_dir'] BIN = config.get("path", os.path.join(MYCROFT_ROOT_PATH, 'mimic', 'bin', 'mimic')) @@ -39,7 +40,7 @@ if not os.path.isfile(BIN): BIN = distutils.spawn.find_executable("mimic") -SUBSCRIBER_VOICES = {'trinity': '/opt/mycroft/voices/mimic_tn'} +SUBSCRIBER_VOICES = {'trinity': join(data_dir, 'voices/mimic_tn')} def download_subscriber_voices(selected_voice): diff --git a/mycroft/util/__init__.py b/mycroft/util/__init__.py index 58252d05e5..e5ba263535 100644 --- a/mycroft/util/__init__.py +++ b/mycroft/util/__init__.py @@ -15,6 +15,8 @@ from __future__ import absolute_import import socket import subprocess +from os.path import join + from threading import Thread from time import sleep @@ -59,6 +61,7 @@ def resolve_resource_file(res_name): Args: res_name (str): a resource path/name """ + config = mycroft.configuration.Configuration.get() # First look for fully qualified file (e.g. a user setting) if os.path.isfile(res_name): @@ -70,7 +73,7 @@ def resolve_resource_file(res_name): return filename # Next look for /opt/mycroft/res/res_name - filename = os.path.expanduser("/opt/mycroft/" + res_name) + filename = os.path.expanduser(join(config['data_dir'], res_name)) if os.path.isfile(filename): return filename diff --git a/mycroft/version/__init__.py b/mycroft/version/__init__.py index e8b80334d0..063d9c3e16 100644 --- a/mycroft/version/__init__.py +++ b/mycroft/version/__init__.py @@ -15,7 +15,9 @@ import json from genericpath import exists, isfile +from os.path import join +from mycroft.configuration import Configuration from mycroft.util.log import LOG @@ -33,18 +35,15 @@ CORE_VERSION_STR = '.'.join(map(str, CORE_VERSION_TUPLE)) class VersionManager(object): - __location = "/opt/mycroft/version.json" - @staticmethod def get(): - if (exists(VersionManager.__location) and - isfile(VersionManager.__location)): + version_file = join(Configuration.get()['data_dir'], 'version.json') + if exists(version_file) and isfile(version_file): try: - with open(VersionManager.__location) as f: + with open(version_file) as f: return json.load(f) - except: - LOG.error("Failed to load version from '%s'" - % VersionManager.__location) + except Exception: + LOG.error("Failed to load version from '%s'" % version_file) return {"coreVersion": None, "enclosureVersion": None} diff --git a/test/unittests/api/test_api.py b/test/unittests/api/test_api.py index 799308275f..0ac1e471d3 100644 --- a/test/unittests/api/test_api.py +++ b/test/unittests/api/test_api.py @@ -22,6 +22,7 @@ import mycroft.configuration from mycroft.util.log import LOG CONFIG = { + 'data_dir': '/opt/mycroft', 'server': { 'url': 'https://api-test.mycroft.ai', 'version': 'v1',