consolidator
/
makeHandlers.py
26 строк · 897.0 Байт
1import os2from MyConfig import MyConfig3
4try:5cur_path = os.path.dirname(os.path.realpath(__file__))6conf = f"{cur_path}\\consolidation.json"7cfg = MyConfig(conf)8hlist:list = cfg.get("handlers",None)9hdict={}10for item in hlist:11hdict[item["key"]]=item["module"]12pattern=""13with open("handlerPattern.py",encoding="utf-8",mode="r") as fp:14pattern=fp.read()15for key in hdict.keys():16fname=f"{cur_path}\\handlers2\\{hdict[key]}.py"17if key!="Рулон" and os.path.isfile(fname):18print(f"{key} -> {fname}")19with open(fname,encoding="utf-8",mode="w") as f:20s=pattern.replace("module_key",key).replace("module_name_var",hdict[key])21f.write(s)22f.flush()23f.close()24print("\tdone")25except Exception as exp:26print(f"error: {exp}")