LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File fix-installation-paths.patch of Package mycroft-core (Project home:alarrosa:packages)

From: Antonio Larrosa <larrosa@kde.org>
Subject: Use system python modules and user's mycroft.conf

This introduces a number of changes:
* Don't use python's virtualenv, but the system python packages
* Add 'use_virtualenvwrapper' config parameter
* Make ~/.mycroft/mycroft.conf have priority over /etc/mycroft/mycroft.conf
* Add a get_config_value function to read config options
* When installing a skill, instead of using pip to install the requirements,
  write requirements.txt to a log file which the user can test manually
  (at ~/.mycroft/mycroft-python-modules.log).
* Write schedule_file to ~/.mycroft/schedule.json instead of under /opt
* Write cache file to ~/.mycroft/web_config_cache.json instead of under /opt
* Install skills to ~/.mycroft/skills

Index: mycroft-core-release-v18.2.0/start-mycroft.sh
===================================================================
--- mycroft-core-release-v18.2.0.orig/start-mycroft.sh
+++ mycroft-core-release-v18.2.0/start-mycroft.sh
@@ -19,14 +19,9 @@ SOURCE="${BASH_SOURCE[0]}"
 script=${0}
 script=${script##*/}
 DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
-scripts_dir="$DIR/scripts"
-mkdir -p $scripts_dir/logs
-
-if [ -z "$WORKON_HOME" ]; then
-    VIRTUALENV_ROOT=${VIRTUALENV_ROOT:-"${HOME}/.virtualenvs/mycroft"}
-else
-    VIRTUALENV_ROOT="$WORKON_HOME/mycroft"
-fi
+logs_dir="/var/logs/mycroft-core"
+#mkdir -p ${logs_dir}
+#chown mycroft-core:mycroft-core ${logs_dir}
 
 function help() {
   echo "${script}:  Mycroft command/service launcher"
@@ -87,8 +82,7 @@ first_time=true
 function launch-process() {
     if ($first_time) ; then
         echo "Initializing..."
-        ${DIR}/scripts/prepare-msm.sh
-        source ${VIRTUALENV_ROOT}/bin/activate
+#        ${DIR}/scripts/prepare-msm.sh
         first_time=false
     fi
 
@@ -102,8 +96,7 @@ function launch-process() {
 function launch-background() {
     if ($first_time) ; then
         echo "Initializing..."
-        ${DIR}/scripts/prepare-msm.sh
-        source ${VIRTUALENV_ROOT}/bin/activate
+#        ${DIR}/scripts/prepare-msm.sh
         first_time=false
     fi
 
@@ -118,7 +111,7 @@ function launch-background() {
     fi
 
     # Launch process in background, sending log to scripts/log/mycroft-*.log
-    python ${_script} $_params >> ${scripts_dir}/logs/mycroft-${1}.log 2>&1 &
+    python ${_script} $_params 2>&1 &
 }
 
 _opt=$1
Index: mycroft-core-release-v18.2.0/stop-mycroft.sh
===================================================================
--- mycroft-core-release-v18.2.0.orig/stop-mycroft.sh
+++ mycroft-core-release-v18.2.0/stop-mycroft.sh
@@ -18,9 +18,6 @@ SOURCE="${BASH_SOURCE[0]}"
 
 script=${0}
 script=${script##*/}
-DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
-SCRIPTS="$DIR/scripts"
-mkdir -p $SCRIPTS/logs
 
 function help() {
   echo "${script}:  Mycroft service stopper"
Index: mycroft-core-release-v18.2.0/mycroft/configuration/mycroft.conf
===================================================================
--- mycroft-core-release-v18.2.0.orig/mycroft/configuration/mycroft.conf
+++ mycroft-core-release-v18.2.0/mycroft/configuration/mycroft.conf
@@ -178,7 +178,10 @@
     "update": true,
     
     // Run a self test at bootup?
-    "test": false
+    "test": false,
+
+    // use virtualenvwrapper (or if false, just use the system python modules)
+    "use_virtualenvwrapper": true
   },
 
   // Level of logs to store, one of  "CRITICAL", "ERROR", "WARNGIN", "INFO", "DEBUG"
@@ -214,6 +217,8 @@
     // Engine.  Options: "mimic", "google", "marytts", "fatts", "espeak", "spdsay"
     "module": "mimic",
     "mimic": {
+      // Path to the mimic binary
+      "path": "/usr/bin/mimic",
       "voice": "ap"
     },
     "espeak": {
@@ -270,6 +275,8 @@
     "channels": 1
   },
   "SkillInstallerSkill": {
+    // Path to the msm script
+    "path": "/usr/bin/msm"
   },
   "Audio": {
     "backends": {
Index: mycroft-core-release-v18.2.0/msm/msm
===================================================================
--- mycroft-core-release-v18.2.0.orig/msm/msm
+++ mycroft-core-release-v18.2.0/msm/msm
@@ -52,11 +52,25 @@ function help() {
   exit 1
 }
 
+function get_config_value() {
+  key="$1"
+  default="$2"
+  value="null"
+  for file in ~/.mycroft/mycroft.conf /etc/mycroft/mycroft.conf ; do
+    if [[ -r ~/.mycroft/mycroft.conf ]] ; then
+        value=$( jq -r "$key" "$file" )
+        if [[ "${value}" != "null" ]] ;  then
+            echo "$value"
+            return
+        fi
+    fi
+  done
+  echo "$default"
+}
+
 # Determine the platform
-mycroft_platform="null"
-if [[ -r /etc/mycroft/mycroft.conf ]] ; then
-   mycroft_platform=$( jq -r '.enclosure.platform' /etc/mycroft/mycroft.conf )
-else
+mycroft_platform="$(get_config_value '.enclosure.platform' 'null')"
+if [[ "${mycroft_platform}" == "null" ]] ; then
    if [[ "$(hostname)" == "picroft" ]] ; then
       mycroft_platform="picroft"
    elif [[ "$(hostname)" =~ "mark_1" ]] ; then
@@ -64,15 +78,7 @@ else
    fi
 fi
 
-# Get the location of the Skill folder
-mycroft_skill_folder="null"
-if [[ -r /etc/mycroft/mycroft.conf ]] ; then
-   mycroft_skill_folder=$( jq -r '.enclosure.skill_folder' /etc/mycroft/mycroft.conf )
-fi
-if [[ ${mycroft_skill_folder} == "null" ]] ; then
-   mycroft_skill_folder="/opt/mycroft/skills"
-fi
-
+mycroft_skill_folder="$(get_config_value '.enclosure.skill_folder' '/opt/mycroft/skills')"
 if [[ ! -d "${mycroft_skill_folder}" ]] ; then
   echo "ERROR: Unable to find/access ${mycroft_skill_folder}!"
   exit 101
@@ -81,18 +87,23 @@ fi
 # Determine if on picroft/mk1?
 picroft_mk1="false"
 vwrap="true"
+use_virtualenvwrapper="$(get_config_value '.enclosure.use_virtualenvwrapper' 'true')"
 if [[ "${mycroft_platform}" == "picroft" ]] || [[ "${mycroft_platform}" == "mycroft_mark_1" ]] ; then
   picroft_mk1="true"
 else
-  if [[ -r /etc/bash_completion.d/virtualenvwrapper ]]; then
-    source /etc/bash_completion.d/virtualenvwrapper
-   elif [[ -r /usr/bin/virtualenvwrapper.sh ]]; then
-    source /usr/bin/virtualenvwrapper.sh
-  else
-    if locate virtualenvwrapper ; then
-      if ! source $(locate virtualenvwrapper) ; then
-        echo "WARNING: Unable to locate virtualenvwrapper.sh, not able to install skills!"
-        vwrap="false"
+  if [[ ${use_virtualenvwrapper} == "true" ]] ; then
+    if [[ -r /etc/bash_completion.d/virtualenvwrapper ]]; then
+      source /etc/bash_completion.d/virtualenvwrapper
+     elif [[ -r /usr/bin/virtualenvwrapper.sh ]]; then
+      source /usr/bin/virtualenvwrapper.sh
+     elif [[ -r /usr/bin/virtualenvwrapper ]]; then
+      source /usr/bin/virtualenvwrapper
+    else
+      if locate virtualenvwrapper ; then
+        if ! source $(locate virtualenvwrapper) ; then
+          echo "WARNING: Unable to locate virtualenvwrapper.sh, not able to install skills!"
+          vwrap="false"
+        fi
       fi
     fi
   fi
@@ -252,7 +263,7 @@ function install() {
   fi
 
   # TODO: Allow skipping virtualwrapper with an option?
-  if [[ "$vwrap" = "false" ]] ; then
+  if [[ "$use_virtualenvwrapper"="true" && "$vwrap" = "false" ]] ; then
     echo "ERROR:  Missing virtualwrapper, cowardly refusing to install skills"
     return 5
   fi
@@ -362,6 +373,12 @@ function run_pip() {
     # NOTE: Must be in the skill directory already...
     name=$*
     if [[ -f "requirements.txt" ]]; then
+      logfile="$HOME/.mycroft/mycroft-python-modules.log"
+      echo "### `date`" >> "$logfile"
+      echo "# Please check manually the following requirements of $PWD are installed:" | tee -a "$logfile"
+      cat "requirements.txt" | tee -a "$logfile"
+      echo "" >> "$logfile"
+      return 0
       echo "  Installing requirements..."
       if [[ "${picroft_mk1}" == "false" ]]; then
         if [[ "${VIRTUAL_ENV}" =~ .mycroft$ ]] ; then
Index: mycroft-core-release-v18.2.0/mycroft/configuration/config.py
===================================================================
--- mycroft-core-release-v18.2.0.orig/mycroft/configuration/config.py
+++ mycroft-core-release-v18.2.0/mycroft/configuration/config.py
@@ -22,6 +22,7 @@ from requests import HTTPError
 
 from mycroft.util.json_helper import load_commented_json
 from mycroft.util.log import LOG
+from mycroft.filesystem import FileSystemAccess
 
 
 def merge_dict(base, delta):
@@ -149,7 +150,8 @@ class RemoteConf(LocalConf):
     def __init__(self, cache=None):
         super(RemoteConf, self).__init__(None)
 
-        cache = cache or '/opt/mycroft/web_config_cache.json'
+        if not cache:
+            cache = join(FileSystemAccess('cache').path, 'web_config_cache.json')
         from mycroft.api import is_paired
         if not is_paired():
             self.load_local(cache)
Index: mycroft-core-release-v18.2.0/mycroft/skills/main.py
===================================================================
--- mycroft-core-release-v18.2.0.orig/mycroft/skills/main.py
+++ mycroft-core-release-v18.2.0/mycroft/skills/main.py
@@ -28,6 +28,7 @@ import mycroft.lock
 from mycroft import MYCROFT_ROOT_PATH
 from mycroft.api import is_paired
 from mycroft.configuration import Configuration
+from mycroft.filesystem import FileSystemAccess
 from mycroft.messagebus.client.ws import WebsocketClient
 from mycroft.messagebus.message import Message
 from mycroft.skills.core import load_skill, create_skill_descriptor, \
@@ -51,7 +52,7 @@ DEBUG = Configuration.get().get("debug",
 skills_config = Configuration.get().get("skills")
 BLACKLISTED_SKILLS = skills_config.get("blacklisted_skills", [])
 PRIORITY_SKILLS = skills_config.get("priority_skills", [])
-SKILLS_DIR = '/opt/mycroft/skills'
+SKILLS_DIR = skills_config.get("directory") or FileSystemAccess('skills').path
 
 installer_config = Configuration.get().get("SkillInstallerSkill")
 MSM_BIN = installer_config.get("path", join(MYCROFT_ROOT_PATH, 'msm', 'msm'))
Index: mycroft-core-release-v18.2.0/mycroft/skills/event_scheduler.py
===================================================================
--- mycroft-core-release-v18.2.0.orig/mycroft/skills/event_scheduler.py
+++ mycroft-core-release-v18.2.0/mycroft/skills/event_scheduler.py
@@ -14,9 +14,10 @@
 #
 import json
 import time
+import os
 from threading import Thread
 
-from os.path import isfile
+from os.path import isfile, expanduser, exists
 
 from mycroft.messagebus.message import Message
 from mycroft.util.log import LOG
@@ -54,7 +55,14 @@ class EventScheduler(Thread):
         self.events = {}
         self.emitter = emitter
         self.isRunning = True
-        self.schedule_file = schedule_file
+        if schedule_file:
+            self.schedule_file = schedule_file
+        else:
+            self.schedule_file = join(expanduser("~"),'.mycroft','schedule.json')
+            # Move the old schedule file to the new location if it exists
+            if exists('/opt/mycroft/schedule.json') and not exists (self.schedule_file):
+                os.rename('/opt/mycroft/schedule.json', self.schedule_file)
+
         if self.schedule_file:
             self.load()
 
Index: mycroft-core-release-v18.2.0/mycroft/tts/mimic_tts.py
===================================================================
--- mycroft-core-release-v18.2.0.orig/mycroft/tts/mimic_tts.py
+++ mycroft-core-release-v18.2.0/mycroft/tts/mimic_tts.py
@@ -38,7 +38,7 @@ if not os.path.isfile(BIN):
     import distutils.spawn
     BIN = distutils.spawn.find_executable("mimic")
 
-SUBSCRIBER_VOICES = {'trinity': '/opt/mycroft/voices/mimic_tn'}
+SUBSCRIBER_VOICES = {'trinity': '/usr/share/mycroft/voices/mimic_tn'}
 
 
 def download_subscriber_voices(selected_voice):
Index: mycroft-core-release-v18.2.0/mycroft/version/__init__.py
===================================================================
--- mycroft-core-release-v18.2.0.orig/mycroft/version/__init__.py
+++ mycroft-core-release-v18.2.0/mycroft/version/__init__.py
@@ -33,7 +33,7 @@ CORE_VERSION_STR = '.'.join(map(str, COR
 
 
 class VersionManager(object):
-    __location = "/opt/mycroft/version.json"
+    __location = "/usr/share/mycroft/version.json"
 
     @staticmethod
     def get():
Index: mycroft-core-release-v18.2.0/skiller.sh
===================================================================
--- mycroft-core-release-v18.2.0.orig/skiller.sh
+++ mycroft-core-release-v18.2.0/skiller.sh
@@ -55,7 +55,23 @@ input_lines() {
     printf -v $var_name "$lines"  # $var_name=$lines
 }
 
-skills_dir=/opt/mycroft/skills
+function get_config_value() {
+  key="$1"
+  default="$2"
+  value="null"
+  for file in ~/.mycroft/mycroft.conf /etc/mycroft/mycroft.conf ; do
+    if [[ -r ~/.mycroft/mycroft.conf ]] ; then
+        value=$( jq -r "$key" "$file" )
+        if [[ "${value}" != "null" ]] ;  then
+            echo "$value"
+            return
+        fi
+    fi
+  done
+  echo "$default"
+}
+
+skills_dir="$(get_config_value '.enclosure.skill_folder' '/opt/mycroft/skills')"
 
 if [ "$#" -gt "2" ] || [ "$1" = "-h" ]; then
     echo "Usage: $0"
Index: mycroft-core-release-v18.2.0/mycroft/skills/audioservice.py
===================================================================
--- mycroft-core-release-v18.2.0.orig/mycroft/skills/audioservice.py
+++ mycroft-core-release-v18.2.0/mycroft/skills/audioservice.py
@@ -78,7 +78,7 @@ class AudioService():
                            audio service.
         """
         tracks = tracks or []
-        if isinstance(tracks, basestring):
+        if isinstance(tracks, str):
             tracks = [tracks]
         elif not isinstance(tracks, list):
             raise ValueError