-
Notifications
You must be signed in to change notification settings - Fork 915
/
config.py
59 lines (40 loc) · 1.36 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
# encoding:utf-8
import json
import os
config = {}
def load_config(config_path = "./config.json"):
global config
if not os.path.exists(config_path):
raise Exception('配置文件不存在,请根据config-template.json模板创建config.json文件')
config_str = read_file(config_path)
# 将json字符串反序列化为dict类型
config = json.loads(config_str)
print("Load config success")
return config
def get_root():
return os.path.dirname(os.path.abspath( __file__ ))
def read_file(path):
with open(path, mode='r', encoding='utf-8') as f:
return f.read()
def conf():
return config
def model_conf(model_type):
return config.get('model').get(model_type)
def model_conf_val(model_type, key):
val = config.get('model').get(model_type).get(key)
if not val:
# common default config
return config.get('model').get(key)
return val
def channel_conf(channel_type):
return config.get('channel').get(channel_type)
def channel_conf_val(channel_type, key, default=None):
val = config.get('channel').get(channel_type).get(key)
if not val:
# common default config
return config.get('channel').get(key, default)
return val
def common_conf_val(key, default=None):
if not config.get('common'):
return default
return config.get('common').get(key, default)