Explorar o código

fix brain loader if a neuron does not have parameter

nico %!s(int64=8) %!d(string=hai) anos
pai
achega
ac57259627
Modificáronse 4 ficheiros con 22 adicións e 16 borrados
  1. 17 10
      core/ConfigurationManager/BrainLoader.py
  2. 1 1
      core/OrderAnalyser.py
  3. 4 4
      test.py
  4. 0 1
      test.yml

+ 17 - 10
core/ConfigurationManager/BrainLoader.py

@@ -60,14 +60,20 @@ class BrainLoader(YAMLLoader):
         """
         neurons = list()
         for neuron_dict in neurons_dict:
-            # print neuron_dict
-            if ConfigurationChecker().check_neuron_dict(neuron_dict):
-                # print "Neurons dict ok"
-                for neuron_name in neuron_dict:
-                    name = neuron_name
-                    parameters = neuron_dict[name]
-                    # print parameters
-                    new_neuron = Neuron(name=name, parameters=parameters)
+            if isinstance(neuron_dict, dict):
+                if ConfigurationChecker().check_neuron_dict(neuron_dict):
+                    # print "Neurons dict ok"
+                    for neuron_name in neuron_dict:
+
+                        name = neuron_name
+                        parameters = neuron_dict[name]
+                        # print parameters
+                        new_neuron = Neuron(name=name, parameters=parameters)
+                        neurons.append(new_neuron)
+            else:
+                # the neuron does not have parameter
+                if ConfigurationChecker().check_neuron_dict(neuron_dict):
+                    new_neuron = Neuron(name=neuron_dict)
                     neurons.append(new_neuron)
 
         return neurons
@@ -106,8 +112,9 @@ class BrainLoader(YAMLLoader):
         # get current script directory path. We are in /an/unknown/path/jarvis/core/ConfigurationManager
         cur_script_directory = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
         # get parent dir. Now we are in /an/unknown/path/jarvis
-        parent_dir = os.path.normpath(cur_script_directory + os.sep + os.pardir)
-        brain_path = parent_dir + "brain.yml"
+        parent_dir = os.path.normpath(cur_script_directory + os.sep + os.pardir + os.sep + os.pardir)
+        brain_path = parent_dir + os.sep + "brain.yml"
+        print brain_path
         logging.debug("Real brain.yml path: %s" % brain_path)
         if os.path.isfile(brain_path):
             return brain_path

+ 1 - 1
core/OrderAnalyser.py

@@ -18,7 +18,7 @@ class OrderAnalyser:
         self.main_controller = main_controller
         self.order = order
         if brain_file is None:
-            self.brain = BrainLoader.get_brain()
+            self.brain = BrainLoader().get_brain()
         else:
             self.brain = BrainLoader(brain_file).get_brain()
         logging.info("Receiver order: %s" % self.order)

+ 4 - 4
test.py

@@ -9,15 +9,15 @@ logger = logging.getLogger()
 logger.setLevel(logging.DEBUG)
 
 
-# # oa = OrderAnalyser("test", brain_file="brain_examples/fr/say_examples.yml")
+oa = OrderAnalyser("say hello")
 #
 # oa = OrderAnalyser("test", brain_file="brain_examples/fr/fr_systemdate.yml")
 #
-# oa.start()
+oa.start()
 
 # cmd = "python jarvis.py start --run-synapse \"say hello\" --brain-file /home/nico/Documents/jarvis/test.yml"
 #
 # os.system(cmd)
 
-crontab_manager = CrontabManager(brain_file="/home/nico/Documents/jarvis/test.yml")
-crontab_manager.load_events_in_crontab()
+# crontab_manager = CrontabManager(brain_file="/home/nico/Documents/jarvis/test.yml")
+# crontab_manager.load_events_in_crontab()

+ 0 - 1
test.yml

@@ -6,4 +6,3 @@
             - "Bonjour monsieur"
     signals:
       - event: "23 23 * * *"
-      - order: "say hello"