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

Method to get database URI.

parent 401392ed
No related branches found
No related tags found
No related merge requests found
...@@ -62,27 +62,27 @@ class AuraConfig: ...@@ -62,27 +62,27 @@ class AuraConfig:
def set(self, key, value): def set(self, key, value):
""" """
Set a property Setter for some specific config property.
@type key: string
@param key: The Key Args:
@type value: mixed key (String): key
@param value: Beliebiger Wert default (*): value
""" """
try: try:
self.__dict__[key] = int(value) self.__dict__[key] = int(value)
except: except:
self.__dict__[key] = str(value) self.__dict__[key] = str(value)
# ------------------------------------------------------------------------------------------ #
def get(self, key, default=None): def get(self, key, default=None):
""" """
get a loaded property Getter for some specific config property.
@type key: string
@param key: Der Key
@type default: mixed
@param default: Beliebiger Wert
"""
Args:
key (String): key
default (*): value
"""
if key not in self.__dict__: if key not in self.__dict__:
if default: if default:
self.set(key, default) self.set(key, default)
...@@ -109,21 +109,22 @@ class AuraConfig: ...@@ -109,21 +109,22 @@ class AuraConfig:
return self.__dict__[key] return self.__dict__[key]
# ------------------------------------------------------------------------------------------ #
def load_config(self): def load_config(self):
""" """
Set config defaults and load settings from file Set config defaults and load settings from file
:return:
""" """
if not os.path.isfile(self.ini_path): if not os.path.isfile(self.ini_path):
self.logger.critical(self.ini_path + " not found :(") self.logger.critical(self.ini_path + " not found :(")
sys.exit(1) sys.exit(1)
# INI einlesen # Read the file
f = open(self.ini_path, 'r') f = open(self.ini_path, 'r')
ini_str = f.read() ini_str = f.read()
f.close() f.close()
# Parse the values
config_parser = ConfigParser() config_parser = ConfigParser()
try: try:
config_parser.read_string(ini_str) config_parser.read_string(ini_str)
...@@ -136,5 +137,19 @@ class AuraConfig: ...@@ -136,5 +137,19 @@ class AuraConfig:
v = config_parser.get(section, key).replace('"', '').strip() v = config_parser.get(section, key).replace('"', '').strip()
self.set(key, v) self.set(key, v)
# Custom overrides
self.set("install_dir", os.path.realpath(__file__ + "../../../..")) self.set("install_dir", os.path.realpath(__file__ + "../../../.."))
self.set("use_test_data", False) self.set("use_test_data", False)
\ No newline at end of file
def get_database_uri(self):
"""
Retrieves the database connection string.
"""
db_name = self.get("db_name")
db_user = self.get("db_user")
db_pass = 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.
Finish editing this message first!
Please register or to comment