LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File msm-add-local-patch-support.patch of Package mycroft-core (Project home:alarrosa:packages)

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
@@ -84,6 +84,13 @@ if [[ ! -d "${mycroft_skill_folder}" ]]
   exit 101
 fi
 
+patch_logfile="$HOME/.mycroft/mycroft-python-modules.log"
+skill_patches_folder="/usr/share/mycroft-core/skill-patches/"
+applied_patch_folder="$HOME/.mycroft/applied-skill-patches"
+if [[ ! -d "${applied_patch_folder}" ]]; then
+  mkdir -p ${applied_patch_folder}
+fi
+
 # Determine if on picroft/mk1?
 picroft_mk1="false"
 vwrap="true"
@@ -237,6 +244,9 @@ function remove() {
      echo -n "Removing '${name}'..."
      send_start_remove
      rm -rf "${name}"
+
+     remove_applied_skill_patch "${name}"
+
      if [[ -d "${mycroft_skill_folder}/${name}" ]] ; then
         # Failed to remove the skill directory
         send_remove_fail "${name}" 249
@@ -253,6 +263,43 @@ function remove() {
   fi
 }
 
+function apply_skill_patch() {
+  name="$1"
+  pflag="$2"
+
+  patchfile="${skill_patches_folder}/${name}.patch"
+  if [[ -r "${patchfile}" ]]; then
+    echo "Applying ${patchfile}"
+    patch -f "${pflag}" < "${patchfile}" \
+      && cp -f "${patchfile}" "${applied_patch_folder}"/ \
+      || echo "ERROR: Couldn't apply ${patchfile}" >> ${patch_logfile}
+  fi
+}
+
+function reverse_skill_patch() {
+  name="$1"
+  pflag="$2"
+
+  patchfile=${applied_patch_folder}/${name}.patch
+  if [[ -r "${patchfile}" ]]; then
+    echo "Reversing ${patchfile}"
+    patch -f "${pflag}" -R < ${patchfile} \
+      && rm -f "${patchfile}" \
+      || echo "ERROR: Couldn't reverse patch ${patchfile}" >> ${patch_logfile}
+  fi
+}
+
+function remove_applied_skill_patch() {
+  name="$1"
+
+  patchfile=${applied_patch_folder}/${name}.patch
+  if [[ -f "${patchfile}" ]]; then
+    echo "Removing ${patchfile}"
+    rm -f "${patchfile}"
+  fi
+}
+
+
 function install() {
   # This could be either a string or a URL
   str=$*
@@ -329,6 +376,9 @@ function install() {
     echo "Installing from: ${repo}"
     send_start_install
     git clone "${repo}" >> /dev/null
+
+    apply_skill_patch "${name}" -p0
+
     if ! cd "${name}" ; then
       echo "ERROR: Unable to access directory ${name}!"
       send_install_fail "${name}" 102
@@ -475,6 +525,10 @@ function update() {
         echo "*.pyc" >> .git/info/exclude
       fi
 
+      # Remove applied patches
+      name=`basename "${d}"`
+      reverse_skill_patch "${name}" -p1
+
       BRANCH="$(git symbolic-ref HEAD 2>/dev/null)"
       BRANCH="${BRANCH##refs/heads/}"
 
@@ -489,6 +543,7 @@ function update() {
         git fetch
         git reset --hard origin/master
         rm -f *.pyc
+	apply_skill_patch "${name}" -p1
         run_pip "${d}"
       else
         echo "Ignoring ${d}, skill has been modified."