From 6d4d84181f00481f9f64ab24faea08db2398e824 Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Sun, 25 Oct 2020 16:15:38 +0100 Subject: [PATCH] Static retrieval of config. #44 --- modules/base/config.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/base/config.py b/modules/base/config.py index af908206..afba671c 100644 --- a/modules/base/config.py +++ b/modules/base/config.py @@ -32,6 +32,7 @@ class AuraConfig: Holds the Engine Configuration as in the file `engine.ini`. """ + instance = None ini_path = "" logger = None @@ -52,6 +53,7 @@ class AuraConfig: self.ini_path = ini_path self.load_config() + AuraConfig.instance = self # Defaults self.set("config_dir", os.path.dirname(ini_path)) @@ -60,6 +62,15 @@ class AuraConfig: + @staticmethod + def config(): + """ + Retrieves the global instances of the configuration. + """ + return AuraConfig.instance + + + def set(self, key, value): """ Setter for some specific config property. @@ -111,6 +122,19 @@ class AuraConfig: + def get_database_uri(self): + """ + Retrieves the database connection string. + """ + db_name = self.get("db_name") + db_user = self.get("db_user") + db_pass = str(self.get("db_pass")) + db_host = self.get("db_host") + db_charset = self.get("db_charset", "utf8") + return "mysql://" + db_user + ":" + db_pass + "@" + db_host + "/" + db_name + "?charset=" + db_charset + + + def load_config(self): """ Set config defaults and load settings from file @@ -138,15 +162,3 @@ class AuraConfig: self.set(key, v) - - - def get_database_uri(self): - """ - Retrieves the database connection string. - """ - db_name = self.get("db_name") - db_user = self.get("db_user") - db_pass = str(self.get("db_pass")) - db_host = self.get("db_host") - db_charset = self.get("db_charset", "utf8") - return "mysql://" + db_user + ":" + db_pass + "@" + db_host + "/" + db_name + "?charset=" + db_charset \ No newline at end of file -- GitLab