-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
43 lines (34 loc) · 1.57 KB
/
helper.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
from json import load
from os import path as px
def load_conf(path=None):
if not path:
path = px.join(px.dirname(__file__), "config.json")
with open(path, "r", encoding="utf-8") as cf:
return load(cf)
cfg = load_conf()
def log_stuff(stuff):
if "log" in cfg and cfg["log"]:
try:
with open(cfg["log"], "a+", encoding="utf-8") as lf:
lf.write("\t".join([str(x) for x in stuff]) + "\n")
except:
pass
def processors4path(service, path):
required_processing = []
for_redis = False
process_args = {}
for pathx in cfg["services"][service]["paths"]:
if pathx in path:
required_processing += cfg["services"][service]["paths"][pathx]["processors"]
if "redis" in cfg["services"][service]["paths"][pathx]:
if cfg["services"][service]["paths"][pathx]["redis"] == 1:
for_redis = True
if required_processing and cfg["services"][service]["process_args"]:
for processor in required_processing:
if processor in cfg["services"][service]["process_args"]:
first_key = list(cfg["services"][service]["process_args"][processor].keys())[0]
process_args[processor] = cfg["services"][service]["process_args"][processor][first_key]
for x in cfg["services"][service]["process_args"][processor]:
if x in path:
process_args[processor] = cfg["services"][service]["process_args"][processor][x]
return required_processing, for_redis, process_args