Passed
Pull Request — develop (#28)
by Antony
01:56
created

build.config.dbconfig()   A

Complexity

Conditions 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
nop 2
1
import os
2
from configparser import ConfigParser
3
4
basedir = os.path.abspath(os.path.dirname(__file__))
5
6
class Config(object):
7
    """Parent config class"""
8
    DEBUG = False
9
    CSRF_ENABLED = True
10
    SECRET = os.getenv('SECRET')
11
12
class TestingConfig(Config):
13
    """Config for testing"""
14
    TESTING = True
15
    DEBUG = True
16
17
class DevelopmentConfig(Config):
18
    """Config for development"""
19
    DEBUG = True
20
21
class StagingConfig(Config):
22
    """Config for Staging"""
23
    DEBUG = True
24
25
class ProductionConfig(Config):
26
    """Config for production"""
27
    DEBUG = False
28
    TESTING = False
29
30
app_config = {
31
    'testing':TestingConfig,
32
    'development':DevelopmentConfig,
33
    'staging': StagingConfig,
34
    'production': ProductionConfig,
35
}
36
37
def dbconfig(filename=basedir+'database.ini', section='postgresql'):
38
    #create a parser
39
    parser = ConfigParser()
40
    #read config file
41
    parser.read(filename)
42
43
    #get section, default to postgres
44
    db={}
45
    if parser.has_section(section):
46
        params = parser.items(section)
47
        for param in params:
48
            db[param[0]] = param[1]
49
        else:
50
            raise Exception('section {0} not found in the {1} file'.format(section,filename))
51
        return db