-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
46 lines (36 loc) · 1.1 KB
/
config.py
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
import os
import re
from flask import config
envre = re.compile(r'''^([^\s=]+)=(?:[\s"']*)(.+?)(?:[\s"']*)$''')
print("Importing variables from .env file")
try:
with open('config.env') as ins:
for line in ins:
match = envre.match(line)
if match is not None:
os.environ[match.group(1)] = match.group(2)
except EnvironmentError:
print("It seems someone forgot to add config.env file")
class BaseConfig:
CACHE_TYPE = os.environ.get('CACHE_TYPE')
# import if use redis cache
CACHE_REDIS_URL = os.environ.get('CACHE_REDIS_URL')
@staticmethod
def init_app(app):
pass
class DevConfig(BaseConfig):
DEBUG = True
ASSETS_DEBUG = True
@classmethod
def init_app(cls, app):
print('THIS APP IS IN DEBUG MODE.')
class ProdConfig(BaseConfig):
SECRET_KEY = os.environ.get('SECRET_KEY') if os.environ.get('SECRET_KEY') else None
@classmethod
def init_app(cls, app):
BaseConfig.init_app(app)
assert os.environ.get('SECRET_KEY'), None
config = {
'dev': DevConfig,
'prod': ProdConfig
}