mycroft-core/mycroft/skills/__main__.py

651 lines
24 KiB
Python
Raw Normal View History

Change to Apache 2.0 license from GPLv3.0 This commit officially switches the mycroft-core repository from GPLv3.0 licensing to Apache 2.0. All dependencies on GPL'ed code have been removed and we have contacted all previous contributors with still-existing code in the repository to agree to this change. Going forward, all contributors will sign a Contributor License Agreement (CLA) by visiting https://mycroft.ai/cla, then they will be included in the Mycroft Project's overall Contributor list, found at: https://github.com/MycroftAI/contributors. This cleanly protects the project, the contributor and all who use the technology to build upon. Futher discussion can be found at this blog post: https://mycroft.ai/blog/right-license/ This commit also removes all __author__="" from the code. These lines are painful to maintain and the etiquette surrounding their maintainence is unclear. Do you remove a name from the list if the last line of code the wrote gets replaced? Etc. Now all contributors are publicly acknowledged in the aforementioned repo, and actual authorship is maintained by Github in a much more effective and elegant way! Finally, a few references to "Mycroft AI" were changed to the correct legal entity name "Mycroft AI Inc." ==== Fixed Issues ==== #403 Update License.md and file headers to Apache 2.0 #400 Update LICENSE.md ==== Documentation Notes ==== Deprecated the ScheduledSkill and ScheduledCRUDSkill classes. These capabilities have been superceded by the more flexible MycroftSkill class methods schedule_event(), schedule_repeating_event(), update_event(), and cancel_event().
2017-10-04 06:28:44 +00:00
# Copyright 2017 Mycroft AI Inc.
#
Change to Apache 2.0 license from GPLv3.0 This commit officially switches the mycroft-core repository from GPLv3.0 licensing to Apache 2.0. All dependencies on GPL'ed code have been removed and we have contacted all previous contributors with still-existing code in the repository to agree to this change. Going forward, all contributors will sign a Contributor License Agreement (CLA) by visiting https://mycroft.ai/cla, then they will be included in the Mycroft Project's overall Contributor list, found at: https://github.com/MycroftAI/contributors. This cleanly protects the project, the contributor and all who use the technology to build upon. Futher discussion can be found at this blog post: https://mycroft.ai/blog/right-license/ This commit also removes all __author__="" from the code. These lines are painful to maintain and the etiquette surrounding their maintainence is unclear. Do you remove a name from the list if the last line of code the wrote gets replaced? Etc. Now all contributors are publicly acknowledged in the aforementioned repo, and actual authorship is maintained by Github in a much more effective and elegant way! Finally, a few references to "Mycroft AI" were changed to the correct legal entity name "Mycroft AI Inc." ==== Fixed Issues ==== #403 Update License.md and file headers to Apache 2.0 #400 Update LICENSE.md ==== Documentation Notes ==== Deprecated the ScheduledSkill and ScheduledCRUDSkill classes. These capabilities have been superceded by the more flexible MycroftSkill class methods schedule_event(), schedule_repeating_event(), update_event(), and cancel_event().
2017-10-04 06:28:44 +00:00
# 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
#
Change to Apache 2.0 license from GPLv3.0 This commit officially switches the mycroft-core repository from GPLv3.0 licensing to Apache 2.0. All dependencies on GPL'ed code have been removed and we have contacted all previous contributors with still-existing code in the repository to agree to this change. Going forward, all contributors will sign a Contributor License Agreement (CLA) by visiting https://mycroft.ai/cla, then they will be included in the Mycroft Project's overall Contributor list, found at: https://github.com/MycroftAI/contributors. This cleanly protects the project, the contributor and all who use the technology to build upon. Futher discussion can be found at this blog post: https://mycroft.ai/blog/right-license/ This commit also removes all __author__="" from the code. These lines are painful to maintain and the etiquette surrounding their maintainence is unclear. Do you remove a name from the list if the last line of code the wrote gets replaced? Etc. Now all contributors are publicly acknowledged in the aforementioned repo, and actual authorship is maintained by Github in a much more effective and elegant way! Finally, a few references to "Mycroft AI" were changed to the correct legal entity name "Mycroft AI Inc." ==== Fixed Issues ==== #403 Update License.md and file headers to Apache 2.0 #400 Update LICENSE.md ==== Documentation Notes ==== Deprecated the ScheduledSkill and ScheduledCRUDSkill classes. These capabilities have been superceded by the more flexible MycroftSkill class methods schedule_event(), schedule_repeating_event(), update_event(), and cancel_event().
2017-10-04 06:28:44 +00:00
# http://www.apache.org/licenses/LICENSE-2.0
#
Change to Apache 2.0 license from GPLv3.0 This commit officially switches the mycroft-core repository from GPLv3.0 licensing to Apache 2.0. All dependencies on GPL'ed code have been removed and we have contacted all previous contributors with still-existing code in the repository to agree to this change. Going forward, all contributors will sign a Contributor License Agreement (CLA) by visiting https://mycroft.ai/cla, then they will be included in the Mycroft Project's overall Contributor list, found at: https://github.com/MycroftAI/contributors. This cleanly protects the project, the contributor and all who use the technology to build upon. Futher discussion can be found at this blog post: https://mycroft.ai/blog/right-license/ This commit also removes all __author__="" from the code. These lines are painful to maintain and the etiquette surrounding their maintainence is unclear. Do you remove a name from the list if the last line of code the wrote gets replaced? Etc. Now all contributors are publicly acknowledged in the aforementioned repo, and actual authorship is maintained by Github in a much more effective and elegant way! Finally, a few references to "Mycroft AI" were changed to the correct legal entity name "Mycroft AI Inc." ==== Fixed Issues ==== #403 Update License.md and file headers to Apache 2.0 #400 Update LICENSE.md ==== Documentation Notes ==== Deprecated the ScheduledSkill and ScheduledCRUDSkill classes. These capabilities have been superceded by the more flexible MycroftSkill class methods schedule_event(), schedule_repeating_event(), update_event(), and cancel_event().
2017-10-04 06:28:44 +00:00
# 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 gc
2018-08-15 18:27:51 +00:00
import json
import os
import sys
2017-02-21 05:43:50 +00:00
import time
from glob import glob
from itertools import chain
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
from os.path import exists, join, basename, dirname, expanduser, isfile
from threading import Timer, Thread, Event
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
import mycroft.lock
2018-05-14 21:20:25 +00:00
from msm import MycroftSkillsManager, SkillRepo, MsmException
from mycroft import dialog
from mycroft.api import is_paired, BackendDown
from mycroft.client.enclosure.api import EnclosureAPI
from mycroft.configuration import Configuration
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
from mycroft.messagebus.client.ws import WebsocketClient
2017-04-06 23:08:23 +00:00
from mycroft.messagebus.message import Message
2017-04-06 01:01:40 +00:00
from mycroft.skills.core import load_skill, create_skill_descriptor, \
MainModule, FallbackSkill
from mycroft.skills.event_scheduler import EventScheduler
from mycroft.skills.intent_service import IntentService
from mycroft.skills.padatious_service import PadatiousService
from mycroft.util import (
connected, wait_while_speaking, reset_sigint_handler,
create_echo_function, create_daemon, wait_for_exit_signal
)
2017-09-18 18:55:58 +00:00
from mycroft.util.log import LOG
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
ws = None
event_scheduler = None
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
skill_manager = None
# Remember "now" at startup. Used to detect clock changes.
start_ticks = time.monotonic()
start_clock = time.time()
DEBUG = Configuration.get().get("debug", False)
skills_config = Configuration.get().get("skills")
BLACKLISTED_SKILLS = skills_config.get("blacklisted_skills", [])
PRIORITY_SKILLS = skills_config.get("priority_skills", [])
2018-01-03 09:04:09 +00:00
installer_config = Configuration.get().get("SkillInstallerSkill")
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
MINUTES = 60 # number of seconds in a minute (syntatic sugar)
2017-04-05 22:11:45 +00:00
2017-03-14 16:12:34 +00:00
2017-02-21 05:43:50 +00:00
def connect():
global ws
2017-02-21 05:43:50 +00:00
ws.run_forever()
def _starting_up():
"""
Start loading skills.
Starts
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
- SkillManager to load/reloading of skills when needed
- a timer to check for internet connection
- adapt intent service
- padatious intent service
"""
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
global ws, skill_manager, event_scheduler
2017-02-21 05:43:50 +00:00
ws.on('intent_failure', FallbackSkill.make_intent_failure_handler(ws))
# Create the Intent manager, which converts utterances to intents
# This is the heart of the voice invoked skill system
2017-11-01 21:47:01 +00:00
service = IntentService(ws)
PadatiousService(ws, service)
event_scheduler = EventScheduler(ws)
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# Create a thread that monitors the loaded skills, looking for updates
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
skill_manager = SkillManager(ws)
skill_manager.daemon = True
# Wait until skills have been loaded once before starting to check
# network connection
skill_manager.load_priority()
skill_manager.start()
check_connection()
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
2017-04-25 22:18:43 +00:00
def check_connection():
2017-08-21 15:05:03 +00:00
"""
Check for network connection. If not paired trigger pairing.
Runs as a Timer every second until connection is detected.
"""
2017-04-25 22:18:43 +00:00
if connected():
enclosure = EnclosureAPI(ws)
if is_paired():
# Skip the sync message when unpaired because the prompt to go to
# home.mycrof.ai will be displayed by the pairing skill
enclosure.mouth_text(dialog.get("message_synching.clock"))
2018-02-25 19:53:04 +00:00
# Force a sync of the local clock with the internet
2018-02-25 19:53:04 +00:00
config = Configuration.get()
platform = config['enclosure'].get("platform", "unknown")
if platform in ['mycroft_mark_1', 'picroft']:
ws.emit(Message("system.ntp.sync"))
time.sleep(15) # TODO: Generate/listen for a message response...
# Check if the time skewed significantly. If so, reboot
skew = abs((time.monotonic() - start_ticks) -
(time.time() - start_clock))
if skew > 60 * 60:
# Time moved by over an hour in the NTP sync. Force a reboot to
# prevent weird things from occcurring due to the 'time warp'.
#
data = {'utterance': dialog.get("time.changed.reboot")}
ws.emit(Message("speak", data))
wait_while_speaking()
# provide visual indicators of the reboot
enclosure.mouth_text(dialog.get("message_rebooting"))
enclosure.eyes_color(70, 65, 69) # soft gray
enclosure.eyes_spin()
# give the system time to finish processing enclosure messages
time.sleep(1.0)
# reboot
ws.emit(Message("system.reboot"))
return
else:
ws.emit(Message("enclosure.mouth.reset"))
time.sleep(0.5)
2017-04-25 22:18:43 +00:00
ws.emit(Message('mycroft.internet.connected'))
# check for pairing, if not automatically start pairing
try:
if not is_paired(ignore_errors=False):
payload = {
'utterances': ["pair my device"],
'lang': "en-us"
}
ws.emit(Message("recognizer_loop:utterance", payload))
else:
from mycroft.api import DeviceApi
api = DeviceApi()
api.update_version()
except BackendDown:
data = {'utterance': dialog.get("backend.down")}
ws.emit(Message("speak", data))
ws.emit(Message("backend.down"))
2017-04-25 22:18:43 +00:00
else:
thread = Timer(1, check_connection)
thread.daemon = True
thread.start()
def _get_last_modified_date(path):
"""
Get last modified date excluding compiled python files, hidden
directories and the settings.json file.
Args:
path: skill directory to check
2018-02-13 09:05:43 +00:00
Returns:
int: time of last change
"""
all_files = []
for root_dir, dirs, files in os.walk(path):
dirs[:] = [d for d in dirs if not d.startswith('.')]
for f in files:
if (not f.endswith('.pyc') and f != 'settings.json' and
not f.startswith('.')):
all_files.append(join(root_dir, f))
# check files of interest in the skill root directory
return max(os.path.getmtime(f) for f in all_files)
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
class SkillManager(Thread):
2017-10-13 09:22:01 +00:00
""" Load, update and manage instances of Skill on this system. """
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
def __init__(self, ws):
super(SkillManager, self).__init__()
self._stop_event = Event()
self._connected_event = Event()
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
self.loaded_skills = {}
self.ws = ws
self.enclosure = EnclosureAPI(ws)
# Schedule install/update of default skill
self.msm = self.create_msm()
self.num_install_retries = 0
self.update_interval = Configuration.get()['skills']['update_interval']
self.update_interval = int(self.update_interval * 60 * MINUTES)
self.dot_msm = join(self.msm.skills_dir, '.msm')
if exists(self.dot_msm):
self.next_download = os.path.getmtime(self.dot_msm) + \
self.update_interval
else:
self.next_download = time.time() - 1
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# Conversation management
ws.on('skill.converse.request', self.handle_converse_request)
# Update on initial connection
ws.on('mycroft.internet.connected',
lambda x: self._connected_event.set())
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# Update upon request
ws.on('skillmanager.update', self.schedule_now)
ws.on('skillmanager.list', self.send_skill_list)
ws.on('skillmanager.deactivate', self.deactivate_skill)
ws.on('skillmanager.keep', self.deactivate_except)
ws.on('skillmanager.activate', self.activate_skill)
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
2018-05-10 17:30:49 +00:00
@staticmethod
def create_msm():
config = Configuration.get()
msm_config = config['skills']['msm']
repo_config = msm_config['repo']
2018-05-23 20:03:01 +00:00
data_dir = expanduser(config['data_dir'])
skills_dir = join(data_dir, msm_config['directory'])
repo_cache = join(data_dir, repo_config['cache'])
2018-05-10 17:30:49 +00:00
platform = config['enclosure'].get('platform', 'default')
return MycroftSkillsManager(
2018-05-15 16:46:44 +00:00
platform=platform, skills_dir=skills_dir,
2018-05-10 17:30:49 +00:00
repo=SkillRepo(
2018-05-15 16:46:44 +00:00
repo_cache, repo_config['url'], repo_config['branch']
2018-05-10 17:30:49 +00:00
), versioned=msm_config['versioned']
)
2018-08-15 18:27:51 +00:00
@staticmethod
def load_skills_data() -> dict:
"""Contains info on how skills should be updated"""
skills_data_file = expanduser('~/.mycroft/skills.json')
if isfile(skills_data_file):
with open(skills_data_file) as f:
return json.load(f)
else:
return {}
@staticmethod
def write_skills_data(data: dict):
skills_data_file = expanduser('~/.mycroft/skills.json')
with open(skills_data_file, 'w') as f:
json.dump(data, f)
def schedule_now(self, message=None):
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
self.next_download = time.time() - 1
@property
def installed_skills_file(self):
venv = dirname(dirname(sys.executable))
if os.access(venv, os.W_OK | os.R_OK | os.X_OK):
return join(venv, '.mycroft-skills')
return expanduser('~/.mycroft/.mycroft-skills')
def load_installed_skills(self) -> set:
skills_file = self.installed_skills_file
if not isfile(skills_file):
return set()
with open(skills_file) as f:
return {
i.strip() for i in f.read().split('\n') if i.strip()
}
def save_installed_skills(self, skill_names):
with open(self.installed_skills_file, 'w') as f:
f.write('\n'.join(skill_names))
def download_skills(self, speak=False):
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
""" Invoke MSM to install default skills and/or update installed skills
Args:
speak (bool, optional): Speak the result? Defaults to False
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
"""
if not connected():
LOG.error('msm failed, network connection not available')
if speak:
self.ws.emit(Message("speak", {
'utterance': dialog.get(
"not connected to the internet")}))
self.next_download = time.time() + 5 * MINUTES
return False
installed_skills = self.load_installed_skills()
default_groups = dict(self.msm.repo.get_default_skill_names())
if self.msm.platform in default_groups:
platform_groups = default_groups[self.msm.platform]
else:
LOG.info('Platform defaults not found, using DEFAULT skills only')
platform_groups = []
default_names = set(chain(default_groups['default'], platform_groups))
default_skill_errored = False
2018-08-15 18:27:51 +00:00
skills_data = self.load_skills_data()
def install_or_update(skill):
"""Install missing defaults and update existing skills"""
2018-08-15 18:27:51 +00:00
if skills_data.get(skill.name, {}).get('beta'):
skill.sha = 'HEAD'
if skill.is_local:
skill.update()
if skill.name not in installed_skills:
skill.update_deps()
elif skill.name in default_names:
try:
skill.install()
except Exception:
if skill.name in default_names:
LOG.warning(
'Failed to install default skill: ' + skill.name
)
nonlocal default_skill_errored
default_skill_errored = True
raise
installed_skills.add(skill.name)
2018-05-14 21:20:25 +00:00
try:
self.msm.apply(install_or_update, self.msm.list())
except MsmException as e:
LOG.error('Failed to update skills: {}'.format(repr(e)))
2018-08-15 18:27:51 +00:00
for skill_name in installed_skills:
skills_data.setdefault(skill_name, {})['installed'] = True
self.write_skills_data(skills_data)
self.save_installed_skills(installed_skills)
if speak:
data = {'utterance': dialog.get("skills updated")}
self.ws.emit(Message("speak", data))
if default_skill_errored and self.num_install_retries < 10:
self.num_install_retries += 1
self.next_download = time.time() + 5 * MINUTES
return False
self.num_install_retries = 0
with open(self.dot_msm, 'a'):
os.utime(self.dot_msm, None)
self.next_download = time.time() + self.update_interval
return True
def _unload_removed(self, paths):
""" Shutdown removed skills.
Arguments:
paths: list of current directories in the skills folder
"""
paths = [p.rstrip('/') for p in paths]
skills = self.loaded_skills
# Find loaded skills that doesn't exist on disk
removed_skills = [str(s) for s in skills.keys() if str(s) not in paths]
for s in removed_skills:
LOG.info('removing {}'.format(s))
try:
LOG.debug('Removing: {}'.format(skills[s]))
skills[s]['instance'].default_shutdown()
except Exception as e:
LOG.exception(e)
self.loaded_skills.pop(s)
def _load_or_reload_skill(self, skill_path):
2017-10-13 09:22:01 +00:00
"""
Check if unloaded skill or changed skill needs reloading
and perform loading if necessary.
Returns True if the skill was loaded/reloaded
2017-10-13 09:22:01 +00:00
"""
skill_path = skill_path.rstrip('/')
skill = self.loaded_skills.setdefault(skill_path, {})
skill.update({
"id": basename(skill_path),
"path": skill_path
})
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# check if folder is a skill (must have __init__.py)
if not MainModule + ".py" in os.listdir(skill_path):
return False
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# getting the newest modified date of skill
modified = _get_last_modified_date(skill_path)
last_mod = skill.get("last_modified", 0)
# checking if skill is loaded and hasn't been modified on disk
if skill.get("loaded") and modified <= last_mod:
return False # Nothing to do!
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# check if skill was modified
elif skill.get("instance") and modified > last_mod:
# check if skill has been blocked from reloading
if (not skill["instance"].reload_skill or
not skill.get('active', True)):
return False
LOG.debug("Reloading Skill: " + basename(skill_path))
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# removing listeners and stopping threads
try:
skill["instance"].default_shutdown()
except Exception:
LOG.exception("An error occured while shutting down {}"
.format(skill["instance"].name))
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
if DEBUG:
gc.collect() # Collect garbage to remove false references
# Remove two local references that are known
refs = sys.getrefcount(skill["instance"]) - 2
if refs > 0:
msg = ("After shutdown of {} there are still "
"{} references remaining. The skill "
"won't be cleaned from memory.")
LOG.warning(msg.format(skill['instance'].name, refs))
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
del skill["instance"]
2018-01-08 04:25:36 +00:00
self.ws.emit(Message("mycroft.skills.shutdown",
{"path": skill_path,
2018-01-08 04:25:36 +00:00
"id": skill["id"]}))
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
skill["loaded"] = True
desc = create_skill_descriptor(skill_path)
skill["instance"] = load_skill(desc,
self.ws, skill["id"],
BLACKLISTED_SKILLS)
skill["last_modified"] = modified
if skill['instance'] is not None:
self.ws.emit(Message('mycroft.skills.loaded',
{'path': skill_path,
'id': skill['id'],
'name': skill['instance'].name,
'modified': modified}))
return True
else:
self.ws.emit(Message('mycroft.skills.loading_failure',
{'path': skill_path,
'id': skill['id']}))
return False
2018-01-07 23:35:13 +00:00
def load_priority(self):
skills = {skill.name: skill for skill in self.msm.list()}
for skill_name in PRIORITY_SKILLS:
skill = skills[skill_name]
if not skill.is_local:
try:
skill.install()
except Exception:
LOG.exception('Downloading priority skill:' + skill.name)
if not skill.is_local:
continue
self._load_or_reload_skill(skill.path)
def remove_git_locks(self):
"""If git gets killed from an abrupt shutdown it leaves lock files"""
for i in glob(join(self.msm.skills_dir, '*/.git/index.lock')):
LOG.warning('Found and removed git lock file: ' + i)
os.remove(i)
def run(self):
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
""" Load skills and update periodically from disk and internet """
self.remove_git_locks()
self._connected_event.wait()
has_loaded = False
# check if skill updates are enabled
update = Configuration.get()["skills"]["auto_update"]
# Scan the file folder that contains Skills. If a Skill is updated,
# unload the existing version from memory and reload from the disk.
while not self._stop_event.is_set():
2018-01-03 09:04:09 +00:00
# Update skills once an hour if update is enabled
if time.time() >= self.next_download and update:
self.download_skills()
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# Look for recently changed skill(s) needing a reload
# checking skills dir and getting all skills there
skill_paths = glob(join(self.msm.skills_dir, '*/'))
still_loading = False
for skill_path in skill_paths:
still_loading = (
self._load_or_reload_skill(skill_path) or
still_loading
)
if not has_loaded and not still_loading and len(skill_paths) > 0:
has_loaded = True
self.ws.emit(Message('mycroft.skills.initialized'))
self._unload_removed(skill_paths)
# Pause briefly before beginning next scan
time.sleep(2)
def send_skill_list(self, message=None):
"""
Send list of loaded skills.
"""
try:
info = {}
for s in self.loaded_skills:
info[basename(s)] = {
'active': self.loaded_skills[s].get('active', True),
'id': self.loaded_skills[s]['id']
}
self.ws.emit(Message('mycroft.skills.list', data=info))
except Exception as e:
LOG.exception(e)
def __deactivate_skill(self, skill):
""" Deactivate a skill. """
for s in self.loaded_skills:
if skill in s:
skill = s
break
try:
self.loaded_skills[skill]['active'] = False
self.loaded_skills[skill]['instance'].default_shutdown()
except Exception as e:
LOG.error('Couldn\'t deactivate skill, {}'.format(repr(e)))
def deactivate_skill(self, message):
""" Deactivate a skill. """
try:
skill = message.data['skill']
if skill in [basename(s) for s in self.loaded_skills]:
self.__deactivate_skill(skill)
except Exception as e:
LOG.error('Couldn\'t deactivate skill, {}'.format(repr(e)))
def deactivate_except(self, message):
""" Deactivate all skills except the provided. """
try:
skill_to_keep = message.data['skill']
LOG.info('DEACTIVATING ALL SKILLS EXCEPT {}'.format(skill_to_keep))
if skill_to_keep in [basename(i) for i in self.loaded_skills]:
for skill in self.loaded_skills:
if basename(skill) != skill_to_keep:
self.__deactivate_skill(skill)
else:
LOG.info('Couldn\'t find skill')
except Exception as e:
LOG.error('Error during skill removal, {}'.format(repr(e)))
def __activate_skill(self, skill):
if not self.loaded_skills[skill].get('active', True):
self.loaded_skills[skill]['loaded'] = False
self.loaded_skills[skill]['active'] = True
def activate_skill(self, message):
""" Activate a deactivated skill. """
try:
skill = message.data['skill']
if skill == 'all':
for s in self.loaded_skills:
self.__activate_skill(s)
else:
for s in self.loaded_skills:
if skill in s:
skill = s
break
self.__activate_skill(skill)
except Exception as e:
LOG.error('Couldn\'t activate skill, {}'.format(repr(e)))
def stop(self):
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
""" Tell the manager to shutdown """
self._stop_event.set()
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
# Do a clean shutdown of all skills
for name, skill_info in self.loaded_skills.items():
instance = skill_info.get('instance')
if instance:
try:
instance.default_shutdown()
except Exception:
LOG.exception('Shutting down skill: ' + name)
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
def handle_converse_request(self, message):
""" Check if the targeted skill id can handle conversation
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
If supported, the conversation is invoked.
"""
skill_id = message.data["skill_id"]
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
utterances = message.data["utterances"]
lang = message.data["lang"]
# loop trough skills list and call converse for skill with skill_id
for skill in self.loaded_skills:
if self.loaded_skills[skill]["id"] == skill_id:
try:
instance = self.loaded_skills[skill]["instance"]
except BaseException:
LOG.error("converse requested but skill not loaded")
2018-04-27 14:12:23 +00:00
self.ws.emit(message.reply("skill.converse.response", {
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
"skill_id": 0, "result": False}))
return
try:
result = instance.converse(utterances, lang)
2018-04-27 14:12:23 +00:00
self.ws.emit(message.reply("skill.converse.response", {
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
"skill_id": skill_id, "result": result}))
return
except BaseException:
LOG.exception(
"Error in converse method for skill " + str(skill_id))
2018-04-27 14:12:23 +00:00
self.ws.emit(message.reply("skill.converse.response",
{"skill_id": 0, "result": False}))
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
def main():
global ws
reset_sigint_handler()
SkillManager, msm messagebus notifications Significantly reworked the loading/updating of Skills. Unified all management under a single SkillManager class. This class runs as a thread that initially loads, upgrades (via MSM) and reloads skills. Removed the independent threads that were being run. The skill updating still happens once an hour, but works in conjunction with the scan to reload modified skills. Also added messagebus notifications from MSM so mycroft-core can pause reloading skills until the installation is complete. Added a new mycroft.messagebus.send module to allow command line interaction with the messagebus, e.g.: python -m mycroft.messagebus.send mycroft.wifi.start python -m mycroft.messagebus.send speak '{"utterance":"hello"}' ==== Fixed Issues ==== MSM installs that have PIP dependencies were failing, as the load would occur after code was retrieved but before PIP install completed. Restart was required to load new skills. ==== Tech Notes ==== TODO: Change the way we manage modules. The auto-load of the remote configuration for the module is silly, slow and wasteful. I made the WebsocketClient.build_url() method static in anticipation of being able to do this more efficiently when the submodule load doesn't hit the remove API automatically. ==== Localization Notes ==== Modified 'sorry I couldn't install default skills' message. ==== Protocol Notes ==== MSM now generates: msm.updating msm.installing msm.install.succeeded { "skill" : name } msm.install.failed { "skill" : name, "error" : code } msm.installed msm.updated msm.removing msm.remove.succeeded { "skill" : name } msm.remove.failed { "skill" : name, "error" : code } msm.removed An update can now be forced by posting 'skillmanager.update' to the messagebus.
2017-10-13 07:21:58 +00:00
# Create PID file, prevent multiple instancesof this service
2017-10-13 09:22:01 +00:00
mycroft.lock.Lock('skills')
# Connect this Skill management process to the websocket
ws = WebsocketClient()
Configuration.init(ws)
2017-04-06 17:45:28 +00:00
ws.on('message', create_echo_function('SKILLS'))
# Startup will be called after websocket is fully live
ws.once('open', _starting_up)
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
create_daemon(ws.run_forever)
wait_for_exit_signal()
shutdown()
2017-04-06 17:45:28 +00:00
2017-04-17 17:25:27 +00:00
def shutdown():
if event_scheduler:
event_scheduler.shutdown()
# Terminate all running threads that update skills
if skill_manager:
skill_manager.stop()
skill_manager.join()
In the 1970s computer users had to understand the arcane syntax of the machines they used. They programed their computers using the machine's native language and hardly gave it a thought. The 1980s birthed a new form of interaction between computers and users. For the first time computers became capable of understanding the most basic form of human communication - pointing and grunting. The mouse and the GUI revolutionized computing and made computers accessible to the masses. We have now entered a third era. We are rapidly approaching a time when computer systems will understand human language and respond using the most natural form of human communication – speech. This is an important development. Some might even call it revolutionary. Despite its importance, however, the technologies that will underpin this new method of interaction are the property of major tech firms who don't necessarily have the public's best interests at heart. Not anymore. Meet Mycroft – the worlds first open source natural language platform. Mycroft understands human language and responds with speech. It is being designed to run on anything from a phone to an automobile and will change the way we interact with open source technologies in profound ways. Our goal here at Mycroft is to improve this technology to the point that when you interact with the software it is impossible to tell if you are talking to a human or a machine. This initial release of the Mycroft software represents a significant effort by the Mycroft community to give the open source world access to this important technology. We are all hoping that the software will be useful to the public and will help to usher in a new era of human machine interaction. Our community welcomes everyone to use Mycroft, improve the software and contribute back to the project. With your help and support we can truly make Mycroft an AI for everyone. Joshua W Montgomery – May 17, 2016
2016-05-20 14:16:01 +00:00
if __name__ == "__main__":
main()