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