Add skill settings to skills
parent
1518444f6d
commit
b6a34f8cee
|
@ -34,7 +34,7 @@ from mycroft.dialog import DialogLoader
|
|||
from mycroft.filesystem import FileSystemAccess
|
||||
from mycroft.messagebus.message import Message
|
||||
from mycroft.util.log import getLogger
|
||||
|
||||
from mycroft.skills.settings import SkillSettings
|
||||
__author__ = 'seanfitz'
|
||||
|
||||
BLACKLISTED_SKILLS = ["send_sms", "media"]
|
||||
|
@ -108,6 +108,7 @@ def load_skill(skill_descriptor, emitter):
|
|||
skill.load_data_files(dirname(skill_descriptor['info'][1]))
|
||||
skill.initialize()
|
||||
logger.info("Loaded " + skill_descriptor["name"])
|
||||
skill.load_settings(skill_descriptor['info'][1] + '/settings.json')
|
||||
return skill
|
||||
else:
|
||||
logger.warn(
|
||||
|
@ -206,6 +207,9 @@ class MycroftSkill(object):
|
|||
def lang(self):
|
||||
return self.config_core.get('lang')
|
||||
|
||||
def load_settings(self, skill_path):
|
||||
self.settings = SkillSettings(skill_path)
|
||||
|
||||
def bind(self, emitter):
|
||||
if emitter:
|
||||
self.emitter = emitter
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright 2017 Mycroft AI, Inc.
|
||||
#
|
||||
# This file is part of Mycroft Core.
|
||||
#
|
||||
# Mycroft Core is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Mycroft Core is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import sys
|
||||
from os.path import isfile
|
||||
|
||||
class SkillSettings(dict):
|
||||
def __init__(self, settings_file):
|
||||
super(SkillSettings, self).__init__()
|
||||
self.path = settings_file
|
||||
if isfile(self.path):
|
||||
with open(self.path) as f:
|
||||
json_data = json.load(f)
|
||||
for key in json_data:
|
||||
self.__setitem__(key, json_data[key])
|
||||
|
||||
def __getitem__(self, key):
|
||||
return super(SkillSettings, self).__getitem__(key)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
return super(SkillSettings, self).__setitem__(key, value)
|
||||
|
||||
def store(self):
|
||||
with open(self.path, 'w')as f:
|
||||
json.dump(self, f)
|
Loading…
Reference in New Issue