Merge pull request #639 from MycroftAI/feature/issue-636

#636 - Removing reference to older skills folders
pull/643/head
Augusto Monteiro 2017-04-07 12:25:57 -07:00 committed by GitHub
commit 36045fd44e
5 changed files with 57 additions and 65 deletions

View File

@ -15,12 +15,12 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>. # along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
import json import json
import inflection
import re import re
from genericpath import exists, isfile from genericpath import exists, isfile
from os.path import join, dirname, expanduser from os.path import join, dirname, expanduser
import inflection
from mycroft.util.log import getLogger from mycroft.util.log import getLogger
__author__ = 'seanfitz, jdorleans' __author__ = 'seanfitz, jdorleans'

View File

@ -66,6 +66,8 @@
"update": true, "update": true,
"test": false "test": false
}, },
"log_level": "DEBUG",
"ignore_logs": ["enclosure.mouth.viseme"],
"session": { "session": {
"ttl": 180 "ttl": 180
}, },

View File

@ -37,12 +37,8 @@ __author__ = 'seanfitz'
signal.signal(signal.SIGCHLD, signal.SIG_IGN) signal.signal(signal.SIGCHLD, signal.SIG_IGN)
PRIMARY_SKILLS = ['intent', 'wake']
BLACKLISTED_SKILLS = ["send_sms", "media"] BLACKLISTED_SKILLS = ["send_sms", "media"]
SKILLS_BASEDIR = dirname(__file__) SKILLS_DIR = "/opt/mycroft/skills"
THIRD_PARTY_SKILLS_DIR = ["/opt/mycroft/third_party", "/opt/mycroft/skills"]
# Note: /opt/mycroft/skills is recommended, /opt/mycroft/third_party
# is for backwards compatibility
MainModule = '__init__' MainModule = '__init__'
@ -151,18 +147,12 @@ def create_skill_descriptor(skill_folder):
return {"name": os.path.basename(skill_folder), "info": info} return {"name": os.path.basename(skill_folder), "info": info}
def load_skills(emitter, skills_root=SKILLS_BASEDIR): def load_skills(emitter, skills_root=SKILLS_DIR):
logger.info("Checking " + skills_root + " for new skills") logger.info("Checking " + skills_root + " for new skills")
skill_list = [] skill_list = []
skills = get_skills(skills_root) for skill in get_skills(skills_root):
for skill in skills: skill_list.append(load_skill(skill, emitter))
if skill['name'] in PRIMARY_SKILLS:
skill_list.append(load_skill(skill, emitter))
for skill in skills:
if (skill['name'] not in PRIMARY_SKILLS and
skill['name'] not in BLACKLISTED_SKILLS):
skill_list.append(load_skill(skill, emitter))
return skill_list return skill_list

View File

@ -22,14 +22,14 @@ import time
from threading import Timer from threading import Timer
import os import os
from os.path import expanduser, exists, join from os.path import exists, join
from mycroft import MYCROFT_ROOT_PATH from mycroft import MYCROFT_ROOT_PATH
from mycroft.configuration import ConfigurationManager from mycroft.configuration import ConfigurationManager
from mycroft.messagebus.client.ws import WebsocketClient from mycroft.messagebus.client.ws import WebsocketClient
from mycroft.messagebus.message import Message from mycroft.messagebus.message import Message
from mycroft.skills.core import THIRD_PARTY_SKILLS_DIR, \ from mycroft.skills.core import load_skill, create_skill_descriptor, \
load_skill, create_skill_descriptor, MainModule MainModule, SKILLS_DIR
from mycroft.skills.intent import Intent from mycroft.skills.intent import Intent
from mycroft.util.log import getLogger from mycroft.util.log import getLogger
@ -79,18 +79,6 @@ def load_watch_skills():
ws.emit(Message("skill_manager", {})) ws.emit(Message("skill_manager", {}))
Intent(ws) Intent(ws)
skills_directories = [os.path.dirname(os.path.abspath(__file__))]
skills_directories = skills_directories + THIRD_PARTY_SKILLS_DIR
try:
config = ConfigurationManager.get().get("skills")
ini_third_party_skills_dir = expanduser(config.get("directory"))
if ini_third_party_skills_dir and exists(ini_third_party_skills_dir):
skills_directories.append(ini_third_party_skills_dir)
except AttributeError as e:
logger.warning(e.message)
skill_reload_thread = Timer(0, watch_skills) skill_reload_thread = Timer(0, watch_skills)
skill_reload_thread.daemon = True skill_reload_thread.daemon = True
skill_reload_thread.start() skill_reload_thread.start()
@ -119,40 +107,38 @@ def clear_skill_events(instance):
def watch_skills(): def watch_skills():
global ws, loaded_skills, last_modified_skill, skills_directories, \ global ws, loaded_skills, last_modified_skill, \
id_counter id_counter
while True: while True:
for dir in skills_directories: if exists(SKILLS_DIR):
if exists(dir): list = filter(lambda x: os.path.isdir(
list = sorted( os.path.join(SKILLS_DIR, x)), os.listdir(SKILLS_DIR))
filter(lambda x: os.path.isdir(os.path.join(dir, x)), for skill_folder in list:
os.listdir(dir))) if skill_folder not in loaded_skills:
for skill_folder in list: loaded_skills[skill_folder] = {}
if skill_folder not in loaded_skills: skill = loaded_skills.get(skill_folder)
loaded_skills[skill_folder] = {} skill["path"] = os.path.join(SKILLS_DIR, skill_folder)
skill = loaded_skills.get(skill_folder) if not MainModule + ".py" in os.listdir(skill["path"]):
skill["path"] = os.path.join(dir, skill_folder) continue
if not MainModule + ".py" in os.listdir(skill["path"]): skill["last_modified"] = max(
os.path.getmtime(root) for root, _, _ in
os.walk(skill["path"]))
modified = skill.get("last_modified", 0)
if skill.get(
"loaded") and modified <= last_modified_skill:
continue
elif skill.get(
"instance") and modified > last_modified_skill:
if not skill["instance"].reload_skill:
continue continue
skill["last_modified"] = max( logger.debug("Reloading Skill: " + skill_folder)
os.path.getmtime(root) for root, _, _ in skill["instance"].shutdown()
os.walk(skill["path"])) clear_skill_events(skill["instance"])
modified = skill.get("last_modified", 0) del skill["instance"]
if skill.get( skill["loaded"] = True
"loaded") and modified <= last_modified_skill: skill["instance"] = load_skill(
continue create_skill_descriptor(skill["path"]), ws)
elif skill.get(
"instance") and modified > last_modified_skill:
if not skill["instance"].reload_skill:
continue
logger.debug("Reloading Skill: " + skill_folder)
skill["instance"].shutdown()
clear_skill_events(skill["instance"])
del skill["instance"]
skill["loaded"] = True
skill["instance"] = load_skill(
create_skill_descriptor(skill["path"]), ws)
last_modified_skill = max( last_modified_skill = max(
map(lambda x: x.get("last_modified"), loaded_skills.values())) map(lambda x: x.get("last_modified"), loaded_skills.values()))
time.sleep(2) time.sleep(2)
@ -163,10 +149,15 @@ def main():
ws = WebsocketClient() ws = WebsocketClient()
ConfigurationManager.init(ws) ConfigurationManager.init(ws)
ignore_logs = ConfigurationManager.get().get("ignore_logs")
def echo(message): def echo(message):
try: try:
_message = json.loads(message) _message = json.loads(message)
if _message.get("type") in ignore_logs:
return
if _message.get("type") == "registration": if _message.get("type") == "registration":
# do not log tokens from registration messages # do not log tokens from registration messages
_message["data"]["token"] = None _message["data"]["token"] = None

View File

@ -14,16 +14,25 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>. # along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
import json
import logging import logging
from os.path import isfile
SYSTEM_CONFIG = '/etc/mycroft/mycroft.conf'
__author__ = 'seanfitz' __author__ = 'seanfitz'
log_level = "DEBUG"
if isfile(SYSTEM_CONFIG):
with open(SYSTEM_CONFIG) as f:
config = json.load(f)
log_level = config.get("log_level", "DEBUG")
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(format=FORMAT, level=logging.DEBUG) logging.basicConfig(format=FORMAT, level=logging.getLevelName(log_level))
logger = logging.getLogger("MYCROFT") logger = logging.getLogger("MYCROFT")
logger.setLevel(logging.DEBUG)
def getLogger(name="MYCROFT"): def getLogger(name="MYCROFT"):