Skip to content

Commit

Permalink
Feature/non hard coded paths (#2058)
Browse files Browse the repository at this point in the history
* Allow ~ when running ensure_directory_exists

* Add custom paths for websettings cache and system conf
  • Loading branch information
forslund authored and Ruthvicp committed Mar 21, 2019
1 parent 0a748b2 commit 9f29649
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 3 additions & 2 deletions mycroft/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from mycroft.util.json_helper import load_commented_json, merge_dict
from mycroft.util.log import LOG

from .locations import DEFAULT_CONFIG, SYSTEM_CONFIG, USER_CONFIG
from .locations import (DEFAULT_CONFIG, SYSTEM_CONFIG, USER_CONFIG,
WEB_CONFIG_CACHE)


def is_remote_list(values):
Expand Down Expand Up @@ -134,7 +135,7 @@ class RemoteConf(LocalConf):
def __init__(self, cache=None):
super(RemoteConf, self).__init__(None)

cache = cache or '/var/tmp/mycroft_web_cache.json'
cache = cache or WEB_CONFIG_CACHE
from mycroft.api import is_paired
if not is_paired():
self.load_local(cache)
Expand Down
23 changes: 21 additions & 2 deletions mycroft/configuration/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,28 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from os.path import join, dirname, expanduser
import os
from os.path import join, dirname, expanduser, exists

DEFAULT_CONFIG = join(dirname(__file__), 'mycroft.conf')
SYSTEM_CONFIG = '/etc/mycroft/mycroft.conf'
SYSTEM_CONFIG = os.environ.get('MYCROFT_SYSTEM_CONFIG',
'/etc/mycroft/mycroft.conf')
USER_CONFIG = join(expanduser('~'), '.mycroft/mycroft.conf')
REMOTE_CONFIG = "mycroft.ai"
WEB_CONFIG_CACHE = os.environ.get('MYCROFT_WEB_CACHE',
'/var/tmp/mycroft_web_cache.json')


def __ensure_folder_exists(path):
""" Make sure the directory for the specified path exists.
Arguments:
path (str): path to config file
"""
directory = dirname(path)
if not exists(directory):
os.makedirs(directory)


__ensure_folder_exists(WEB_CONFIG_CACHE)
__ensure_folder_exists(USER_CONFIG)
3 changes: 3 additions & 0 deletions mycroft/util/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def ensure_directory_exists(directory, domain=None):
"""
if domain:
directory = os.path.join(directory, domain)

# Expand and normalize the path
directory = os.path.normpath(directory)
directory = os.path.expanduser(directory)

if not os.path.isdir(directory):
try:
Expand Down

0 comments on commit 9f29649

Please sign in to comment.