Merge pull request #639 from MycroftAI/feature/issue-636
#636 - Removing reference to older skills folderspull/643/head
commit
36045fd44e
|
@ -15,12 +15,12 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
|
||||
import json
|
||||
|
||||
import inflection
|
||||
import re
|
||||
from genericpath import exists, isfile
|
||||
from os.path import join, dirname, expanduser
|
||||
|
||||
import inflection
|
||||
|
||||
from mycroft.util.log import getLogger
|
||||
|
||||
__author__ = 'seanfitz, jdorleans'
|
||||
|
|
|
@ -66,6 +66,8 @@
|
|||
"update": true,
|
||||
"test": false
|
||||
},
|
||||
"log_level": "DEBUG",
|
||||
"ignore_logs": ["enclosure.mouth.viseme"],
|
||||
"session": {
|
||||
"ttl": 180
|
||||
},
|
||||
|
|
|
@ -37,12 +37,8 @@ __author__ = 'seanfitz'
|
|||
|
||||
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
|
||||
|
||||
PRIMARY_SKILLS = ['intent', 'wake']
|
||||
BLACKLISTED_SKILLS = ["send_sms", "media"]
|
||||
SKILLS_BASEDIR = dirname(__file__)
|
||||
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
|
||||
SKILLS_DIR = "/opt/mycroft/skills"
|
||||
|
||||
MainModule = '__init__'
|
||||
|
||||
|
@ -151,18 +147,12 @@ def create_skill_descriptor(skill_folder):
|
|||
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")
|
||||
skill_list = []
|
||||
skills = get_skills(skills_root)
|
||||
for skill in skills:
|
||||
if skill['name'] in PRIMARY_SKILLS:
|
||||
skill_list.append(load_skill(skill, emitter))
|
||||
for skill in get_skills(skills_root):
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -22,14 +22,14 @@ import time
|
|||
from threading import Timer
|
||||
|
||||
import os
|
||||
from os.path import expanduser, exists, join
|
||||
from os.path import exists, join
|
||||
|
||||
from mycroft import MYCROFT_ROOT_PATH
|
||||
from mycroft.configuration import ConfigurationManager
|
||||
from mycroft.messagebus.client.ws import WebsocketClient
|
||||
from mycroft.messagebus.message import Message
|
||||
from mycroft.skills.core import THIRD_PARTY_SKILLS_DIR, \
|
||||
load_skill, create_skill_descriptor, MainModule
|
||||
from mycroft.skills.core import load_skill, create_skill_descriptor, \
|
||||
MainModule, SKILLS_DIR
|
||||
from mycroft.skills.intent import Intent
|
||||
from mycroft.util.log import getLogger
|
||||
|
||||
|
@ -79,18 +79,6 @@ def load_watch_skills():
|
|||
ws.emit(Message("skill_manager", {}))
|
||||
|
||||
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.daemon = True
|
||||
skill_reload_thread.start()
|
||||
|
@ -119,40 +107,38 @@ def clear_skill_events(instance):
|
|||
|
||||
|
||||
def watch_skills():
|
||||
global ws, loaded_skills, last_modified_skill, skills_directories, \
|
||||
global ws, loaded_skills, last_modified_skill, \
|
||||
id_counter
|
||||
|
||||
while True:
|
||||
for dir in skills_directories:
|
||||
if exists(dir):
|
||||
list = sorted(
|
||||
filter(lambda x: os.path.isdir(os.path.join(dir, x)),
|
||||
os.listdir(dir)))
|
||||
for skill_folder in list:
|
||||
if skill_folder not in loaded_skills:
|
||||
loaded_skills[skill_folder] = {}
|
||||
skill = loaded_skills.get(skill_folder)
|
||||
skill["path"] = os.path.join(dir, skill_folder)
|
||||
if not MainModule + ".py" in os.listdir(skill["path"]):
|
||||
if exists(SKILLS_DIR):
|
||||
list = filter(lambda x: os.path.isdir(
|
||||
os.path.join(SKILLS_DIR, x)), os.listdir(SKILLS_DIR))
|
||||
for skill_folder in list:
|
||||
if skill_folder not in loaded_skills:
|
||||
loaded_skills[skill_folder] = {}
|
||||
skill = loaded_skills.get(skill_folder)
|
||||
skill["path"] = os.path.join(SKILLS_DIR, skill_folder)
|
||||
if not MainModule + ".py" in os.listdir(skill["path"]):
|
||||
continue
|
||||
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
|
||||
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
|
||||
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)
|
||||
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(
|
||||
map(lambda x: x.get("last_modified"), loaded_skills.values()))
|
||||
time.sleep(2)
|
||||
|
@ -163,10 +149,15 @@ def main():
|
|||
ws = WebsocketClient()
|
||||
ConfigurationManager.init(ws)
|
||||
|
||||
ignore_logs = ConfigurationManager.get().get("ignore_logs")
|
||||
|
||||
def echo(message):
|
||||
try:
|
||||
_message = json.loads(message)
|
||||
|
||||
if _message.get("type") in ignore_logs:
|
||||
return
|
||||
|
||||
if _message.get("type") == "registration":
|
||||
# do not log tokens from registration messages
|
||||
_message["data"]["token"] = None
|
||||
|
|
|
@ -14,16 +14,25 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
from os.path import isfile
|
||||
|
||||
SYSTEM_CONFIG = '/etc/mycroft/mycroft.conf'
|
||||
|
||||
__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'
|
||||
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
|
||||
logging.basicConfig(format=FORMAT, level=logging.getLevelName(log_level))
|
||||
logger = logging.getLogger("MYCROFT")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
def getLogger(name="MYCROFT"):
|
||||
|
|
Loading…
Reference in New Issue