# -*- coding: utf-8 -*- """把复选框单元格插进设备行。 为什么单独写这一步: 第一次跑 add_batch_delete.py 时 rows 锚点没匹配上, 但后端接口加成功了;第二次跑就因为"delete_many 已存在"整个跳过, 于是行里的复选框一直没加上(表头有、行里没有)。 """ from __future__ import annotations import ast import sys from pathlib import Path RELAY = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\relay" r"\relay.py") def main() -> int: lines = RELAY.read_text(encoding="utf-8").splitlines(keepends=True) if any("class=pickcell" in line and "" not in line for line in lines): print(" 复选框已经在行里了") return 0 out = [] done = False for index, line in enumerate(lines): out.append(line) if done: continue # 找 rows.append( 之后紧跟的 "" 行 if line.strip() == '""' and index > 0 and "rows.append(" in lines[index - 1]: indent = " " * (len(line) - len(line.lstrip())) out.append(indent + "# 批量删除用的复选框,value 是 deviceId\n") out.append(indent + '""\n') out.append(indent + "f''\n") out.append(indent + '""\n') done = True if not done: print(" [失败] 没找到插入点") return 1 text = "".join(out) ast.parse(text) RELAY.write_text(text, encoding="utf-8", newline="\n") print(" 已插入复选框单元格") for index, line in enumerate(text.splitlines(), 1): if "rows.append" in line: for offset in range(index - 1, min(index + 8, len(text.splitlines()))): print(f" {offset + 1}: {text.splitlines()[offset]}") break return 0 if __name__ == "__main__": sys.exit(main())