Total Complexity | 3 |
Total Lines | 55 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |