Completed
Push — develop ( 3a3795...1e8194 )
by Antony
03:19 queued 01:31
created

build.config.dbconfig()   A

Complexity

Conditions 3

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