-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
89 lines (79 loc) · 2.11 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import env
from configparser import SafeConfigParser
def config_path():
return os.path.dirname(os.path.realpath(__file__))
def config_env():
try:
return env.ENVIRONMENT
except AttributeError:
package,environment = os.path.basename(config_path()).split("-")
return environment
def config_database(env=None):
if env is None:
env = config_env()
db = {};
db[env] = db.get(env,{});
parser = SafeConfigParser();
parser.read(os.path.join(config_path(),'database.config'))
for key,value in parser.items(env):
db[env][key] = value;
connection = db[env];
return connection;
def config_sqlalchemy(cxn):
uri = 'mysql+pymysql://{user}:{passwd}@{host}/{db}'.format(**cxn)
return uri
def config_lcdn(env):
resource_urls = {}
parser = SafeConfigParser();
parser.read(os.path.join(config_path(),'lcdn.cfg'))
for key,value in parser.items(env):
resource_urls[key] = value;
return resource_urls
class Config:
NAME = env.APPNAME
# setup
DIRECTORY = config_path()
ENVIRONMENT = config_env()
# data comes from somewhere
DATABASE = config_database()
# sqlalchemy
SQLALCHEMY_DATABASE_URI = config_sqlalchemy(DATABASE)
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_TRACK_MODIFICATIONS = False
# deliver libraries
#LCDN_PATH = os.path.join(config_path(),'/lcdn/static')
#LCDN_ALLOWED = {
# 'css': 'text/css',
# 'js': 'application/javascript'
#}
#LCDN_SRC = config_lcdn('remote')
# form support
SECRET_KEY = ''
# unicode on
JSON_AS_ASCII = False
# debugging off
DEBUG = False
TESTING = False
PRINT_ENV = False
# config modifications
class LiveConfig(Config):
JSON_AS_ASCII = False
class DevConfig(Config):
DEBUG = True
TESTING = True
PRINT_ENV = True
class LocalConfig(Config):
DEBUG = True
TESTING = True
PRINT_ENV = True
#LCDN_SRC = config_lcdn('local')
#LCDN_SRC = config_lcdn('remote')
configs = {
"live": "config.LiveConfig",
"local": "config.LocalConfig",
"dev": "config.DevConfig",
"development": "config.DevConfig",
"experimental": "config.DevConfig",
"default": "config.DevConfig"
}