Files
feature-next-arch/_fix_dup.py
2026-08-10 10:00:52 +08:00

62 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sys
path = r'C:\Users\jsmbz\Documents\flutter-app-02\lib\features\home\presentation\widgets\map\testmap_pages.dart'
with open(path, 'r', encoding='utf-8') as f:
lines = f.readlines()
# 删除重复的 failMsg 声明和重复的检查逻辑 (行2402-2411,0索引为2401-2410)
# 但行号可能因之前的编辑有偏移,用内容查找
del_start = None
del_end = None
for i, line in enumerate(lines):
if 'debugPrint' in line and '创建设备任务失败' in line and 'failure' in line:
# 检查下一行是否是重复的 final failMsg
if i+1 < len(lines) and 'final failMsg = failure.toString();' in lines[i+1]:
# 找到了重复的起点
del_start = i # debugPrint 行
# 找到这个重复块的结束:下一个 return; 之后的 },
for j in range(i+2, len(lines)):
if '// 其他失败' in lines[j] or (lines[j].strip() == 'return;' and 'taskCubit.clearCurrentTask();' in lines[j-1]):
# 更精确:找到 " return;" 且前一行是 taskCubit.clearCurrentTask
if lines[j].strip() == 'return;':
del_end = j + 1 # 包含 return; 行
break
if del_end is None:
# 备选:找到下一个 ' },' (fold 成功回调的开始)
for j in range(i+2, len(lines)):
if lines[j].strip().startswith('},') and 'taskId' in lines[j+1]:
del_end = j
break
break
if del_start is not None and del_end is not None:
print(f'Deleting lines {del_start+1} to {del_end}')
for k in range(del_start, del_end):
print(f' DEL: L{k+1}: {lines[k].rstrip()}')
del lines[del_start:del_end]
else:
print('Could not find duplicate block, checking for alternate pattern...')
# 备选:直接搜索两个 final failMsg 行
failmsg_lines = []
for i, line in enumerate(lines):
if 'final failMsg = failure.toString();' in line:
failmsg_lines.append(i)
print(f'failMsg lines: {[l+1 for l in failmsg_lines]}')
if len(failmsg_lines) >= 2:
# 删除第二个 failMsg 及它所属的整个重复检查块
second = failmsg_lines[1]
# 从第二个 failMsg 前一行 (debugPrint) 开始删
start = second - 1
# 找到这个 block 的结束
end = second + 8 # 大约8行后是这个重复块的结束
print(f'Alt: deleting lines {start+1} to {end}')
for k in range(start, min(end, len(lines))):
print(f' DEL: L{k+1}: {lines[k].rstrip()}')
del lines[start:end]
with open(path, 'w', encoding='utf-8', newline='') as f:
f.writelines(lines)
print('DONE')