Skip to content

Commit

Permalink
Fix multiple reloads of skills at startup
Browse files Browse the repository at this point in the history
==== Fixed Issues ====
MycroftAI#1001

====  Tech Notes ====
Previously the skills were reloaded a couple of times during startup
since updates of the .pyc file and possible the settings.json file were
made.

This commit adds a bit finer control over which files to check.
Currently all files in skill root except ones ending in .pyc and the
settings.json are checked along with all visible subdirectories
  • Loading branch information
forslund committed Aug 18, 2017
1 parent f2f5925 commit 70bd15a
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions mycroft/skills/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,30 @@ def check_connection():


def _get_last_modified_date(path):
last_date = 0
# getting all recursive paths
for root, _, _ in os.walk(path):
f = root.replace(path, "")
# checking if is a hidden path
if not f.startswith(".") and not f.startswith("/."):
last_date = max(last_date, os.path.getmtime(path + f))
"""
Get last modified date excluding compiled python files, hidden
directories and the settings.json file.
Arg:
path: skill directory to check
Returns: time of last change
"""
last_date = 0
root_dir, subdirs, files = os.walk(path).next()
# get subdirs and remove hidden ones
subdirs = [s for s in subdirs if not s.startswith('.')]
for subdir in subdirs:
for root, _, _ in os.walk(os.path.join(path, subdir)):
base = os.path.basename(root)
# checking if is a hidden path
if not base.startswith(".") and not base.startswith("/."):
last_date = max(last_date, os.path.getmtime(root))

# check files of interest in the skill root directory
files = [f for f in files
if not f.endswith('.pyc') and f != 'settings.json']
for f in files:
last_date = max(last_date, os.path.getmtime(os.path.join(path, f)))
return last_date


Expand Down Expand Up @@ -196,12 +212,12 @@ def _watch_skills():
"loaded") and modified <= last_modified_skill:
continue
# checking if skill was modified
elif skill.get(
"instance") and modified > last_modified_skill:
elif skill.get("instance") and modified > last_modified_skill:
# checking if skill should be reloaded
if not skill["instance"].reload_skill:
continue
logger.debug("Reloading Skill: " + skill_folder)
logger.debug("Reloading Skill: " + skill_folder +
str(modified))
# removing listeners and stopping threads
skill["instance"].shutdown()
del skill["instance"]
Expand Down

0 comments on commit 70bd15a

Please sign in to comment.