feat: 增加 ZMQ 调试服务器并完善设置功能

This commit is contained in:
2026-04-20 06:37:46 +08:00
parent 41af2ada45
commit d16ec03da6
11 changed files with 289 additions and 58 deletions
+43 -19
View File
@@ -2,35 +2,59 @@ from heurams.services.config import ConfigDict
from heurams.services.logger import get_logger
logger = get_logger(__name__)
def epath(dct, path: str = '', default=None, parents=False):
def epath(dct, path: str = '', default=None, parents=False, enable_modify=False, new_value=None):
if not path:
return dct
path = path.rstrip('.')
path = path.lstrip('.')
target = dct
for i in path.split('.'):
keys = path.split('.')
logger.debug(f"处理 EPATH {path}, {new_value}")
for idx, i in enumerate(keys):
is_last = (idx == len(keys) - 1)
# 处理字典键
logger.debug(f'处理 {i}, {(isinstance(target, dict) or isinstance(target, ConfigDict))} {i in target}')
if (isinstance(target, dict) or isinstance(target, ConfigDict)) and i in target:
target = target[i]
# 处理列表索引
elif i.startswith('[') and i.endswith(']') and isinstance(target, (list, tuple)):
idx = int(i[1:-1])
if 0 <= idx < len(target):
target = target[idx]
elif parents:
while len(target) <= idx:
target.append(None)
target[idx] = {}
target = target[idx]
if is_last and enable_modify:
# 最后一次循环执行修改
if (isinstance(target, dict) or isinstance(target, ConfigDict)):
target[i] = new_value
return new_value
elif i.startswith('[') and i.endswith(']') and isinstance(target, (list, tuple)):
idx_num = int(i[1:-1])
if 0 <= idx_num < len(target):
target[idx_num] = new_value
return new_value
elif parents:
while len(target) <= idx_num:
target.append(None)
target[idx_num] = new_value
return new_value
else:
return default
else:
return default
elif parents:
target[i] = {}
target = target[i]
else:
return default
if (isinstance(target, dict) or isinstance(target, ConfigDict)) and i in target:
target = target[i]
elif i.startswith('[') and i.endswith(']') and isinstance(target, (list, tuple)):
idx_num = int(i[1:-1])
if 0 <= idx_num < len(target):
target = target[idx_num]
elif parents:
while len(target) <= idx_num:
target.append(None)
target[idx_num] = {}
target = target[idx_num]
else:
return default
elif parents:
target[i] = {}
target = target[i]
else:
return default
return target