Skip to content
Snippets Groups Projects
Commit 6d4d8418 authored by David Trattnig's avatar David Trattnig
Browse files

Static retrieval of config. #44

parent 4791a65c
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ class AuraConfig: ...@@ -32,6 +32,7 @@ class AuraConfig:
Holds the Engine Configuration as in the file `engine.ini`. Holds the Engine Configuration as in the file `engine.ini`.
""" """
instance = None
ini_path = "" ini_path = ""
logger = None logger = None
...@@ -52,6 +53,7 @@ class AuraConfig: ...@@ -52,6 +53,7 @@ class AuraConfig:
self.ini_path = ini_path self.ini_path = ini_path
self.load_config() self.load_config()
AuraConfig.instance = self
# Defaults # Defaults
self.set("config_dir", os.path.dirname(ini_path)) self.set("config_dir", os.path.dirname(ini_path))
...@@ -60,6 +62,15 @@ class AuraConfig: ...@@ -60,6 +62,15 @@ class AuraConfig:
@staticmethod
def config():
"""
Retrieves the global instances of the configuration.
"""
return AuraConfig.instance
def set(self, key, value): def set(self, key, value):
""" """
Setter for some specific config property. Setter for some specific config property.
...@@ -111,6 +122,19 @@ class AuraConfig: ...@@ -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): def load_config(self):
""" """
Set config defaults and load settings from file Set config defaults and load settings from file
...@@ -138,15 +162,3 @@ class AuraConfig: ...@@ -138,15 +162,3 @@ class AuraConfig:
self.set(key, v) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment