Total Complexity | 4 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |