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