设备命令修改
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""分析 D:\ACP 下所有 .ACP 测试项/子程序的结构。"""
|
||||
import json, os, glob
|
||||
|
||||
def walk_steps(steps, depth, out):
|
||||
for s in steps:
|
||||
st = s.get("StepType")
|
||||
name = s.get("Name")
|
||||
ind = " " * depth
|
||||
if st == "方法":
|
||||
m = s.get("Method") or {}
|
||||
full = m.get("FullName", "?")
|
||||
cls = full.split(".")[-1]
|
||||
params = []
|
||||
for p in (m.get("Parameters") or []):
|
||||
if p.get("Category") == 0: # Input
|
||||
v = p.get("Value")
|
||||
if p.get("IsUseVar"):
|
||||
v = f"${p.get('VariableName')}"
|
||||
params.append(f"{p.get('Name')}={v}")
|
||||
out.append(f"{ind}[方法] {name} <- {cls}({', '.join(params)})")
|
||||
elif st == "子程序":
|
||||
out.append(f"{ind}[子程序] {name}")
|
||||
sp = s.get("SubProgram")
|
||||
if sp and sp.get("StepCollection"):
|
||||
walk_steps(sp["StepCollection"], depth + 1, out)
|
||||
elif st == "循环开始":
|
||||
lc = s.get("LoopCount")
|
||||
out.append(f"{ind}[循环开始] 次数={lc}")
|
||||
elif st == "循环结束":
|
||||
out.append(f"{ind}[循环结束]")
|
||||
elif st == "跳转":
|
||||
out.append(f"{ind}[跳转] {name} expr={s.get('OKExpression')}")
|
||||
else:
|
||||
out.append(f"{ind}[{st}] {name}")
|
||||
|
||||
dirs = [r"D:\ACP\测试项", r"D:\ACP\子程序"]
|
||||
for d in dirs:
|
||||
for fp in sorted(glob.glob(os.path.join(d, "*.ACP"))):
|
||||
print("=" * 70)
|
||||
print("FILE:", os.path.basename(fp))
|
||||
with open(fp, encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
out = []
|
||||
walk_steps(data.get("StepCollection") or [], 0, out)
|
||||
# 只打印前 60 行,避免过长
|
||||
for line in out[:60]:
|
||||
print(line)
|
||||
if len(out) > 60:
|
||||
print(f"... (共 {len(out)} 步,已省略)")
|
||||
# 参数
|
||||
print(" -- Parameters --")
|
||||
for p in (data.get("Parameters") or []):
|
||||
print(f" {p.get('Name')} = {p.get('Value')}")
|
||||
Reference in New Issue
Block a user