forked from hjdhnx/dr_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.py
48 lines (45 loc) · 1.19 KB
/
env.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File : env.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/11/21
from utils.cfg import cfg
import ujson
from controllers.service import storage_service
def get_env():
new_conf = cfg
lsg = storage_service()
store_conf_dict = lsg.getStoreConfDict()
new_conf.update(store_conf_dict)
# print(new_conf)
env = {
'ali_token': new_conf.ALI_TOKEN,
'js_proxy':new_conf.JS_PROXY,
'fl':'{{fl}}' # 防止被依赖代理
}
ENV = new_conf.ENV.strip()
if ENV:
# print(ENV)
try:
ENV = ujson.loads(ENV)
except Exception as e:
print(f'自定义环境变量有误,不是合法json:{e}')
ENV = {}
if ENV:
env.update(ENV)
# print(env)
return env
def update_env(env_key:str,env_value:str):
lsg = storage_service()
env = lsg.getItem('ENV')
ENV = {}
try:
ENV = ujson.loads(env)
except:
env = '{}'
if env_key:
ENV[env_key] = env_value
new_env = ujson.dumps(ENV,ensure_ascii=False)
print(new_env)
lsg.setItem('ENV',new_env)
return ENV