From 986cf55d1b6631de51f740f5970ac32dda601758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Forslund?= Date: Tue, 23 May 2017 07:47:06 +0200 Subject: [PATCH] Use exit status of msm to determine install success - msm will now return immediately if an error occurs - install_default_skills now checks exit status instead of text output --- msm/msm | 15 +++++++++++++-- ...rry I couldn't install default skills.dialog | 2 ++ mycroft/skills/main.py | 17 +++++++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 mycroft/res/text/en-us/sorry I couldn't install default skills.dialog diff --git a/msm/msm b/msm/msm index b0a9bad8bb..6f1a8ec768 100755 --- a/msm/msm +++ b/msm/msm @@ -23,6 +23,8 @@ # This script assists in the installation and management of # skills loaded from Github. +set -e + mycroft_skill_folder="/opt/mycroft/skills" mycroft_virtualenv=~/.virtualenvs/mycroft/bin/activate @@ -37,8 +39,17 @@ function help() { echo -e "example: msm install https://github.com/ethanaward/demo_skill.git\n" } -function install() { + +function goto_skills_dir { + if [ ! -d $mycroft_skill_folder ]; then + echo "Couldn't install skill, $mycroft_skill_folder does not exist" + exit 1 + fi cd $mycroft_skill_folder +} + +function install() { + goto_skills_dir if [ -z "$2" ]; then echo "You must pass the git url or skill name" exit 1 @@ -80,7 +91,7 @@ function install() { } function update() { - cd $mycroft_skill_folder + goto_skills_dir for d in $(ls -d */); do if git -C "$d" rev-parse --git-dir > /dev/null 2>&1; then cd $d diff --git a/mycroft/res/text/en-us/sorry I couldn't install default skills.dialog b/mycroft/res/text/en-us/sorry I couldn't install default skills.dialog new file mode 100644 index 0000000000..bf0b94fb94 --- /dev/null +++ b/mycroft/res/text/en-us/sorry I couldn't install default skills.dialog @@ -0,0 +1,2 @@ +sorry I couldn't install default skills +an error occured while installing default skills diff --git a/mycroft/skills/main.py b/mycroft/skills/main.py index 36f823620f..ea2337315e 100644 --- a/mycroft/skills/main.py +++ b/mycroft/skills/main.py @@ -57,16 +57,25 @@ def connect(): def install_default_skills(speak=True): + """ + Install default skill set using msm. + + Args: + speak (optional): Enable response for success. Default True + """ if exists(MSM_BIN): - p = subprocess.Popen(MSM_BIN + " default", stderr=subprocess.STDOUT, - stdout=subprocess.PIPE, shell=True) - t = p.communicate()[0] - if t.splitlines()[-1] == "Installed!" and speak: + res = subprocess.call(MSM_BIN + " default", stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, shell=True) + if res == 0 and speak: ws.emit(Message("speak", { 'utterance': mycroft.dialog.get("skills updated")})) elif not connected(): ws.emit(Message("speak", { 'utterance': mycroft.dialog.get("no network connection")})) + elif res != 0: + ws.emit(Message("speak", { + 'utterance': mycroft.dialog.get( + "sorry I couldn't install default skills")})) else: logger.error("Unable to invoke Mycroft Skill Manager: " + MSM_BIN)