2022-10-17 16:31:48 +02:00
|
|
|
from configparser import ConfigParser
|
|
|
|
|
|
|
|
|
2022-10-17 19:50:25 +02:00
|
|
|
def config(filename="database.ini", section="production"):
|
2022-10-17 16:31:48 +02:00
|
|
|
# create a parser
|
|
|
|
parser = ConfigParser()
|
|
|
|
# read config file
|
|
|
|
parser.read(filename)
|
|
|
|
|
|
|
|
# get section, default to postgresql
|
|
|
|
db = {}
|
|
|
|
if parser.has_section(section):
|
|
|
|
params = parser.items(section)
|
|
|
|
for param in params:
|
|
|
|
db[param[0]] = param[1]
|
|
|
|
else:
|
|
|
|
raise Exception(
|
2024-05-16 11:18:42 +02:00
|
|
|
f"Section {section} not found in the {filename} file"
|
2022-10-17 16:31:48 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
return db
|