File fix-skills-directories.patch of Package python-msm
Index: msm-0.5.17/msm/configuration.py
===================================================================
--- /dev/null
+++ msm-0.5.17/msm/configuration.py
@@ -0,0 +1,62 @@
+
+# Copyright 2017 Mycroft AI Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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, exists, isfile, expanduser
+from .json_helper import load_commented_json
+
+SYSTEM_CONFIG = '/etc/mycroft/mycroft.conf'
+USER_CONFIG = join(expanduser('~'), '.mycroft/mycroft.conf')
+
+class LocalConf(dict):
+ """
+ Config dict from file.
+ """
+ def __init__(self, path):
+ super(LocalConf, self).__init__()
+ if path:
+ self.path = path
+ self.load_local(path)
+
+ def load_local(self, path):
+ """
+ Load local json file into self.
+
+ Args:
+ path (str): file to load
+ """
+ if exists(path) and isfile(path):
+ try:
+ config = load_commented_json(path)
+ for key in config:
+ self.__setitem__(key, config[key])
+
+ except Exception as e:
+ print("Error loading configuration '{}'".format(path))
+ print(repr(e))
+
+def get_skills_configuration_value(key):
+ for config_file in (USER_CONFIG, SYSTEM_CONFIG):
+ config = LocalConf(config_file)
+ directory = config.get('skills').get(key)
+ return directory
+
+ return None
+
+def get_skills_directory():
+ return get_skills_configuration_value('directory') or "/opt/mycroft/skills"
+
+def get_skills_repo_directory():
+ return get_skills_configuration_value('repo_directory') or "/opt/mycroft/.skills-repo"
Index: msm-0.5.17/msm/mycroft_skills_manager.py
===================================================================
--- msm-0.5.17.orig/msm/mycroft_skills_manager.py
+++ msm-0.5.17/msm/mycroft_skills_manager.py
@@ -30,6 +30,7 @@ from msm import GitException
from typing import Dict, List
from msm import GitException
+from msm.configuration import get_skills_directory
from msm.exceptions import (MsmException, SkillNotFound, MultipleSkillMatches,
AlreadyInstalled)
from msm.skill_entry import SkillEntry
@@ -68,7 +69,7 @@ from msm import GitException
class MycroftSkillsManager(object):
SKILL_GROUPS = {'default', 'mycroft_mark_1', 'picroft', 'kde'}
- DEFAULT_SKILLS_DIR = "/opt/mycroft/skills"
+ DEFAULT_SKILLS_DIR = get_skills_directory()
def __init__(self, platform='default', skills_dir=None, repo=None,
versioned=True):
Index: msm-0.5.17/msm/json_helper.py
===================================================================
--- /dev/null
+++ msm-0.5.17/msm/json_helper.py
@@ -0,0 +1,69 @@
+# Copyright 2017 Mycroft AI Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+#
+import json
+
+
+def load_commented_json(filename):
+ """ Loads an JSON file, ignoring comments
+
+ Supports a trivial extension to the JSON file format. Allow comments
+ to be embedded within the JSON, requiring that a comment be on an
+ independent line starting with '//' or '#'.
+
+ NOTE: A file created with these style comments will break strict JSON
+ parsers. This is similar to but lighter-weight than "human json"
+ proposed at https://hjson.org
+
+ Args:
+ filename (str): path to the commented JSON file
+
+ Returns:
+ obj: decoded Python object
+ """
+ with open(filename) as f:
+ contents = f.read()
+
+ return json.loads(uncomment_json(contents))
+
+
+def uncomment_json(commented_json_str):
+ """ Removes comments from a JSON string.
+
+ Supporting a trivial extension to the JSON format. Allow comments
+ to be embedded within the JSON, requiring that a comment be on an
+ independent line starting with '//' or '#'.
+
+ Example...
+ {
+ // comment
+ 'name' : 'value'
+ }
+
+ Args:
+ commented_json_str (str): a JSON string
+
+ Returns:
+ str: uncommented, legal JSON
+ """
+ lines = commented_json_str.splitlines()
+ # remove all comment lines, starting with // or #
+ nocomment = []
+ for line in lines:
+ stripped = line.lstrip()
+ if stripped.startswith("//") or stripped.startswith("#"):
+ continue
+ nocomment.append(line)
+
+ return " ".join(nocomment)
Index: msm-0.5.17/msm/skill_repo.py
===================================================================
--- msm-0.5.17.orig/msm/skill_repo.py
+++ msm-0.5.17/msm/skill_repo.py
@@ -29,6 +29,7 @@ from git.exc import GitCommandError
from msm import git_to_msm_exceptions
from msm.exceptions import MsmException
from msm.util import Git
+from msm.configuration import get_skills_repo_directory
import logging
LOG = logging.getLogger(__name__)
@@ -36,7 +37,7 @@ LOG = logging.getLogger(__name__)
class SkillRepo(object):
def __init__(self, path=None, url=None, branch=None):
- self.path = path or "/opt/mycroft/.skills-repo"
+ self.path = path or get_skills_repo_directory()
self.url = url or "https://github.com/MycroftAI/mycroft-skills"
self.branch = branch or "18.08"
self.repo_info = {}