浏览代码

[Feature] Singleton Brain to be continued

monf 8 年之前
父节点
当前提交
e7ba7862ee
共有 4 个文件被更改,包括 9 次插入17 次删除
  1. 5 2
      core/ConfigurationManager/BrainLoader.py
  2. 1 3
      core/ConfigurationManager/SettingLoader.py
  3. 3 1
      core/Models/Brain.py
  4. 0 11
      test.py

+ 5 - 2
core/ConfigurationManager/BrainLoader.py

@@ -14,7 +14,7 @@ from core.Models.Synapse import Synapse
 logging.basicConfig()
 logger = logging.getLogger("kalliope")
 
-
+@Singleton
 class BrainLoader(object):
 
     def __init__(self):
@@ -40,7 +40,8 @@ class BrainLoader(object):
         # create a new brain
         brain = Brain.Instance()
 
-        if not isinstance(brain, Brain):
+        if brain.is_loaded is False:
+
             brain.brain_yaml = dict_brain
             # create list of Synapse
             synapses = list()
@@ -61,6 +62,8 @@ class BrainLoader(object):
             # check that no synapse have the same name than another
             if not ConfigurationChecker().check_synapes(synapses):
                 brain = None
+
+            brain.is_loaded = True
         return brain
 
     @staticmethod

+ 1 - 3
core/ConfigurationManager/SettingLoader.py

@@ -30,9 +30,7 @@ class SettingNotFound(Exception):
 class SettingLoader(object):
 
     def __init__(self):
-        # Todo check how to provide the file_path
-        self.settings = self._get_settings()
-        self.yaml_config = self._get_yaml_config()
+        pass
 
     @classmethod
     def _get_yaml_config(cls, file_path=None):

+ 3 - 1
core/Models/Brain.py

@@ -2,8 +2,10 @@ from core.Models import Singleton
 
 
 @Singleton
-class Brain(object):
+class Brain:
+
     def __init__(self, synapses=None, brain_file=None, brain_yaml=None):
         self.synapses = synapses
         self.brain_file = brain_file
         self.brain_yaml = brain_yaml
+        self.is_loaded = False

+ 0 - 11
test.py

@@ -1,8 +1,6 @@
 # coding: utf8
 import logging
 
-from flask import Flask
-
 from core import OrderAnalyser
 from core import Utils
 from core.ConfigurationManager import SettingLoader
@@ -16,16 +14,7 @@ logger.setLevel(logging.DEBUG)
 
 
 brain = BrainLoader.get_brain()
-#
-# order = "bonjour"
-# oa = OrderAnalyser(order=order, brain=brain)
-# oa.start()
-
-
 
-app = Flask(__name__)
-flask_api = FlaskAPI(app, port=5000, brain=brain)
-flask_api.start()