浏览代码

[REFACTOR] ++improvement Configuration management

monf 8 年之前
父节点
当前提交
76741a1c1d

+ 21 - 0
core/ConfigurationManager/BrainLoader.py

@@ -0,0 +1,21 @@
+from YAMLLoader import yamlloader
+
+class BrainLoader(yamlloader):
+
+    FILE_NAME = "brain.yml"
+
+    def __init__(self):
+        self.fileName =  self.FILE_NAME
+        self.filePath = "../../" + self.fileName
+        yamlloader.__init__(self, self.filePath)
+
+    def __init__(self, filename):
+        self.fileName = filename;
+        self.filePath = "../../" + self.fileName
+        yamlloader.__init__(self, self.filePath)
+
+    def get_config(self):
+        return yamlloader.get_config(self)
+
+
+

+ 0 - 0
core/ConfigurationManager/ConfigurationManager.py


+ 13 - 0
core/ConfigurationManager/SettingLoader.py

@@ -0,0 +1,13 @@
+from YAMLLoader import yamlloader
+
+class SettingLoader(yamlloader) :
+
+    FILE_NAME = "settings.yml"
+
+    def __init__(self, yamlloader):
+        self.fileName =  self.FILE_NAME;
+        self.filePath = "../../" + self.fileName
+        yamlloader.__init__(self, self.filePath)
+
+    def get_config(self):
+        return yamlloader.get_config(self)

+ 18 - 0
core/ConfigurationManager/YAMLLoader.py

@@ -0,0 +1,18 @@
+import os
+import yaml
+
+class YAMLLoader() :
+
+    def __init__(self, file):
+        self.file = file
+    def get_config(self):
+        """
+        Load settings file
+        :return: cfg : the brain configuration file
+        """
+        # Load settings. Will be used to convert slot number into GPIO pin number
+        __location__ = os.path.realpath(
+            os.path.join(os.getcwd(), os.path.dirname(__file__)))
+        with open(os.path.join(__location__, self.file)) as ymlfile:
+            cfg = yaml.load(ymlfile)
+        return cfg

+ 0 - 0
core/ConfigurationManager/__init__.py