-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
70 lines (51 loc) · 1.75 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
from dotenv import load_dotenv
# DOT_ENV_FILE holds the name of file in which all environment vars are set.
# If present, we try to load the vars from this file. it will continue gracefully if file not found etc.
dot_env_file = os.environ.get("DOT_ENV")
abs_path = os.path.realpath(dot_env_file) if dot_env_file else None
if abs_path and os.path.isfile(abs_path):
load_dotenv(abs_path, verbose=True)
class BaseConfig(object):
DEBUG = True
TESTING = False
SECRET_KEY = os.environ['SECRET_KEY']
SITE_NAME = os.environ.get("SITE_NAME", "site_name.com")
LOG_LEVEL = "DEBUG"
REDIS_HOST = os.environ.get("REDIS_HOST", "localhost")
GOOGLE_API_KEY = os.environ['GOOGLE_API_KEY']
@classmethod
def init_app(cls, app):
pass
class DevelopmentConfig(BaseConfig):
@classmethod
def init_app(cls, app):
super(DevelopmentConfig, cls).init_app(app)
class TestingConfig(DevelopmentConfig):
TESTING = True
@classmethod
def init_app(cls, app):
super(TestingConfig, cls).init_app(app)
class ProductionConfig(BaseConfig):
LOG_LEVEL = "ERROR"
@classmethod
def init_app(cls, app):
super(ProductionConfig, cls).init_app(app)
class EnvironmentName:
"""
use this class to refer to names of environments.
"""
development = 'development'
testing = 'testing'
production = 'production'
default = 'default'
@classmethod
def all_names(cls):
return [attr for attr in dir(cls)
if not (attr.startswith('__') or attr == 'all_names')]
configs = {
EnvironmentName.development: DevelopmentConfig,
EnvironmentName.testing: TestingConfig,
EnvironmentName.production: ProductionConfig,
EnvironmentName.default: DevelopmentConfig
}