2016-05-26 16:16:13 +00:00
|
|
|
# Copyright 2016 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/>.
|
|
|
|
|
|
|
|
|
2016-05-20 14:16:01 +00:00
|
|
|
import json
|
2016-07-18 20:45:11 +00:00
|
|
|
from os.path import expanduser, exists
|
2016-05-20 14:16:01 +00:00
|
|
|
|
2016-06-17 18:47:25 +00:00
|
|
|
from mycroft.configuration import ConfigurationManager
|
2016-05-20 14:16:01 +00:00
|
|
|
from mycroft.messagebus.client.ws import WebsocketClient
|
2016-06-17 18:47:25 +00:00
|
|
|
from mycroft.skills.core import load_skills, THIRD_PARTY_SKILLS_DIR
|
2016-05-20 14:16:01 +00:00
|
|
|
from mycroft.util.log import getLogger
|
2016-09-17 02:08:53 +00:00
|
|
|
|
2016-05-20 14:16:01 +00:00
|
|
|
logger = getLogger("Skills")
|
|
|
|
|
|
|
|
__author__ = 'seanfitz'
|
|
|
|
|
2016-12-17 19:53:22 +00:00
|
|
|
ws = None
|
2016-05-20 14:16:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def load_skills_callback():
|
2016-12-17 19:53:22 +00:00
|
|
|
global ws
|
|
|
|
load_skills(ws)
|
2016-09-17 02:08:53 +00:00
|
|
|
config = ConfigurationManager.get().get("skills")
|
2016-06-17 18:50:00 +00:00
|
|
|
|
2016-06-17 18:47:25 +00:00
|
|
|
try:
|
2016-11-25 01:37:11 +00:00
|
|
|
ini_third_party_skills_dir = expanduser(config.get("directory"))
|
2016-06-17 18:47:25 +00:00
|
|
|
except AttributeError as e:
|
|
|
|
logger.warning(e.message)
|
|
|
|
|
2016-11-15 21:06:44 +00:00
|
|
|
for loc in THIRD_PARTY_SKILLS_DIR:
|
|
|
|
if exists(loc):
|
|
|
|
load_skills(client, loc)
|
|
|
|
|
2016-06-17 18:47:25 +00:00
|
|
|
if ini_third_party_skills_dir and exists(ini_third_party_skills_dir):
|
2016-12-17 19:53:22 +00:00
|
|
|
load_skills(ws, ini_third_party_skills_dir)
|
2016-05-20 14:16:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def connect():
|
2016-12-17 19:53:22 +00:00
|
|
|
global ws
|
|
|
|
ws.run_forever()
|
2016-05-20 14:16:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2016-12-17 19:53:22 +00:00
|
|
|
global ws
|
|
|
|
ws = WebsocketClient()
|
|
|
|
ConfigurationManager.init(ws)
|
2016-05-20 14:16:01 +00:00
|
|
|
|
|
|
|
def echo(message):
|
|
|
|
try:
|
|
|
|
_message = json.loads(message)
|
|
|
|
|
2016-09-04 00:59:39 +00:00
|
|
|
if _message.get("type") == "registration":
|
2016-05-20 14:16:01 +00:00
|
|
|
# do not log tokens from registration messages
|
2016-09-04 01:24:18 +00:00
|
|
|
_message["data"]["token"] = None
|
2016-05-20 14:16:01 +00:00
|
|
|
message = json.dumps(_message)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
logger.debug(message)
|
|
|
|
|
2016-12-17 19:53:22 +00:00
|
|
|
ws.on('message', echo)
|
|
|
|
ws.once('open', load_skills_callback)
|
|
|
|
ws.run_forever()
|
2016-05-20 14:16:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|