fix: 對 CMTS 設定階層實施強化排查機制

This commit is contained in:
swpa 2026-05-28 13:28:39 +08:00
parent a868d82bd5
commit f8285f7ff7
1 changed files with 14 additions and 14 deletions

View File

@ -75,27 +75,27 @@ def parse_cli_to_tree(cli_text: str) -> dict:
stripped = line.strip() stripped = line.strip()
indent = len(line) - len(line.lstrip()) indent = len(line) - len(line.lstrip())
# 🌟 嚴格判斷 1如果遇到縮排退回 (包含縮排退回的 !),代表當前深度的區塊已結束 # 🌟 嚴格判斷 1遇到「真實指令」縮排退回才代表區塊結束
if indent < current_indent: # (加上 stripped != '!'防止設備偶發的「0 縮排 !」導致區塊被誤殺)
if indent < current_indent and stripped != '!':
return nodes, i return nodes, i
# 🌟 嚴格判斷 2處理同層級的 ! # 🌟 嚴格判斷 2處理 ! (無論縮排多少,都當純分隔符消耗掉)
if stripped == '!': if stripped == '!':
# 能走到這裡,代表 indent >= current_indent
# 這是對應當前層級的結束符號或分隔符,我們將其消耗掉並繼續,絕對不提早 return
i += 1 i += 1
continue continue
# 探測是否有子節點 # 🌟 探測是否有子節點 (強化版:往下尋找第一個「非 !」的真實指令來判斷)
has_children = False has_children = False
if i + 1 < len(lines): next_i = i + 1
next_line = lines[i+1] while next_i < len(lines) and lines[next_i].strip() == '!':
next_stripped = next_line.strip() next_i += 1
# 只有當下一行不是 ! 且縮排大於當前行時,才判定為有子節點
if next_stripped != '!': if next_i < len(lines):
next_indent = len(next_line) - len(next_line.lstrip()) next_line = lines[next_i]
if next_indent > indent: next_indent = len(next_line) - len(next_line.lstrip())
has_children = True if next_indent > indent:
has_children = True
if has_children: if has_children:
children, next_i = build_raw_tree(i + 1, next_indent) children, next_i = build_raw_tree(i + 1, next_indent)