forked from arivers444/Project_Finale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
28 lines (21 loc) · 969 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# This file was adapted from http://www.postgresqltutorial.com/postgresql-python/connect/
# The following config() function reads in the database.ini file and returns the connection
# parameters as a dictionary. This function will be imported in to the main python script:
#!/usr/bin/python
from configparser import ConfigParser
def config(filename='database.ini', section='postgresql'):
# create a parser
parser = ConfigParser()
# read config file
parser.read(filename)
# get section, default to postgresql
db = {}
# Checks to see if section (postgresql) parser exists
if parser.has_section(section):
params = parser.items(section)
for param in params:
db[param[0]] = param[1]
# Returns an error if a parameter is called that is not listed in the initialization file
else:
raise Exception('Section {0} not found in the {1} file'.format(section, filename))
return db