ソースを参照

[Review] #148 Fix error when neuron already exists + update version

monf 8 年 前
コミット
20a1177390
3 ファイル変更20 行追加17 行削除
  1. 1 1
      kalliope/_version.py
  2. 17 14
      kalliope/core/ResourcesManager.py
  3. 2 2
      kalliope/settings.yml

+ 1 - 1
kalliope/_version.py

@@ -1,2 +1,2 @@
 # https://www.python.org/dev/peps/pep-0440/
-version_str = "0.3.0"
+version_str = "0.4.0"

+ 17 - 14
kalliope/core/ResourcesManager.py

@@ -122,26 +122,29 @@ class ResourcesManager(object):
         new_absolute_neuron_path = self.settings.resources.neuron_folder + os.sep + neuron_name
         try:
             os.rename(self.tmp_path, new_absolute_neuron_path)
-            return new_absolute_neuron_path
         except OSError:
             # the folder already exist
             Utils.print_warning("The neuron %s already exist in the resource directory" % neuron_name)
             # remove the cloned repo
             shutil.rmtree(self.tmp_path)
+            new_absolute_neuron_path = None
+        finally:
+            return new_absolute_neuron_path
 
     def install_neuron(self):
         # rename the folder
         new_neuron_path = self._rename_temp_neuron_folder()
-        install_file_path = new_neuron_path + os.sep + INSTALL_FILE_NAME
-        Utils.print_info("Starting neuron installation")
-        # ask the sudo password
-        pswd = getpass.getpass('Sudo password:')
-        ansible_neuron_parameters = {
-            "task_file": install_file_path,
-            "sudo": True,
-            "sudo_user": "root",
-            "sudo_password": pswd
-        }
-        neuron = Neuron(name="ansible_playbook", parameters=ansible_neuron_parameters)
-        NeuronLauncher.start_neuron(neuron)
-        Utils.print_success("Neuron %s installed" % self.dna_file["neuron_name"])
+        if new_neuron_path is not None:
+            install_file_path = new_neuron_path + os.sep + INSTALL_FILE_NAME
+            Utils.print_info("Starting neuron installation")
+            # ask the sudo password
+            pswd = getpass.getpass('Sudo password:')
+            ansible_neuron_parameters = {
+                "task_file": install_file_path,
+                "sudo": True,
+                "sudo_user": "root",
+                "sudo_password": pswd
+            }
+            neuron = Neuron(name="ansible_playbook", parameters=ansible_neuron_parameters)
+            NeuronLauncher.start_neuron(neuron)
+            Utils.print_success("Neuron %s installed" % self.dna_file["neuron_name"])

+ 2 - 2
kalliope/settings.yml

@@ -117,8 +117,8 @@ default_synapse: "Default-synapse"
 # ---------------------------
 # resource directory path
 # ---------------------------
-#resource_directory:
-#  neuron: "resources/neurons"
+resource_directory:
+  neuron: "/tmp/resources/neurons"
 #  stt: "resources/stt"
 #  tts: "resources/tts"
 #  trigger: "resources/trigger"