"""把 MeetingsScreen.kt 里那些**已经搬进 :nodekit 的定义**删掉。 ## 为什么要写脚本而不是手改 要删的有 19 段、合计约 1200 行,散在 8485 行的文件里。手工删两次的代价: · PowerShell 的 `String.Replace` **匹配失败不报错**,删不掉还不知道 · 按行号剪贴会算错下标(这个仓库里真的把整个文件追加过一遍) 所以这里按行号删,但**每段都带断言** —— 断言的文本对不上就整个中止, 一个字节都不写。宁可报错,不要写坏。 ## 断言里为什么用"内容"而不是"行号" 行号是我读了文件得到的,但删除过程中只要有一段错位,后面全错。 把每段的关键行内容一起断言,等于顺手校验了行号没算错。 用法: python scripts/migrate-nodekit-strip.py # 预演(只检查,不写) python scripts/migrate-nodekit-strip.py --write # 真的写 """ import io import os import sys try: sys.stdout.reconfigure(encoding="utf-8", errors="replace") except Exception: pass HERE = os.path.dirname(os.path.abspath(__file__)) KT = os.path.join( HERE, "..", "android", "app", "src", "main", "java", "com", "doubao", "lynxclone", "ui", "MeetingsScreen.kt", ) # (起始行, 结束行, [(行号, 必须包含的文本), ...]) —— 行号 1-based,闭区间 BLOCKS = [ (545, 555, [ (545, "private const val NODE_W = 116f"), (547, "private const val NODE_H = 88f"), (553, "private const val CANVAS_W = 900f"), (555, "private const val CANVAS_H = 800f"), ]), (3527, 3583, [ (3529, "一个引脚。照 UE 蓝图分四类"), (3553, "private data class PinSpec("), (3579, "fun accepts_(fromKind: String): Boolean"), (3583, "}"), ]), (3601, 3603, [ (3601, "任何数据类型都能接"), (3603, 'private val ANY_DATA = listOf("str", "bool", "num", "list")'), ]), (3607, 3637, [ (3609, "运算表。必须和引擎里的"), (3615, "private val OPS_UI = listOf("), (3635, '"append" to "追加到列表"'), (3637, ")"), ]), (3641, 3667, [ (3643, "private fun opSpec(key: String)"), (3665, 'else -> Triple("num", "num", 2)'), (3667, "}"), ]), (3671, 3675, [ (3673, "private fun opLabel(key: String)"), (3675, "OPS_UI.firstOrNull"), ]), (3679, 3871, [ (3681, "节点的输入引脚。"), (3695, "private fun inputPins("), (3871, "}"), ]), (3875, 4041, [ (3877, "右边一列的引脚(从上到下)。"), (3893, "private fun outputPins("), (4041, "}"), ]), (4045, 4067, [ (4045, "UE 蓝图式的节点尺寸"), (4051, "private const val HEADER_H = 24f"), (4065, "private const val PORT_R = 5.5f"), (4067, "private const val PORT_HIT = 19f"), ]), (4071, 4091, [ (4073, "private fun nodeHeight("), (4091, "}"), ]), (4095, 4115, [ (4097, "引脚的几何位置"), (4107, "private fun pinPos(node: MeetingNode, index: Int, isOutput: Boolean)"), (4115, "}"), ]), (4119, 4133, [ (4119, "找输出引脚的序号"), (4121, "private fun outPinIndex("), (4133, "}"), ]), (4137, 4195, [ (4139, "输入端口的位置。"), (4151, "private fun portIn("), (4195, "}"), ]), (4199, 4227, [ (4199, "输出端口的位置"), (4201, "private fun portOut("), (4227, "}"), ]), (4727, 4739, [ (4727, "变量类型的中文名"), (4729, "private fun typeLabel(type: String)"), (4739, "}"), ]), (5665, 5765, [ (5665, "连线种类的中文名"), (5709, "private val ANY_COLOR = Color(0xFF9C27B0)"), (5715, "private fun pinColorOf(pin: PinSpec): Color"), (5723, "private fun pinColor(kind: String): Color"), (5747, "private fun pinBorder(kind: String): Color"), (5753, "private fun kindLabel(kind: String): String"), (5765, "}"), ]), (5841, 5843, [ (5841, "private val EXEC_COLOR = Color(0xFFE8EAED)"), (5843, "private val EXEC_BORDER = Color(0xFF5F6368)"), ]), (5917, 5971, [ (5919, "画布能铺多远(dp)。"), (5931, "private const val CANVAS_MARGIN = 900f"), (5937, "private fun canvasSize(nodes: List)"), (5957, "private fun clampPan("), (5971, ")"), ]), (7025, 7055, [ (7025, "private fun nodeColor(type: String): Color"), (7053, "else -> Doubao.Blue"), (7055, "}"), ]), ] def main(): write = "--write" in sys.argv with io.open(KT, encoding="utf-8") as fh: lines = fh.read().split("\n") total = len(lines) print(f"{os.path.basename(KT)}:{total} 行") # 先全部断言,一处不对就退出(不写文件) for start, end, checks in BLOCKS: if not (1 <= start <= end <= total): print(f"!! 区块 {start}-{end} 越界(文件只有 {total} 行)") return 1 for ln, want in checks: got = lines[ln - 1] if 1 <= ln <= total else "<越界>" if want not in got: print(f"!! 第 {ln} 行断言失败") print(f" 期望包含:{want}") print(f" 实际内容:{got}") return 1 print(f"断言全过({len(BLOCKS)} 段)") # 从后往前删,前面的行号才不会偏移 removed = 0 for start, end, _ in sorted(BLOCKS, key=lambda b: -b[0]): del lines[start - 1:end] removed += end - start + 1 print(f" 删除 {start}-{end}({end - start + 1} 行)") print(f"合计删除 {removed} 行,剩 {len(lines)} 行") if not write: print("(预演模式,没有写文件。加 --write 才真写)") return 0 with io.open(KT, "w", encoding="utf-8", newline="") as fh: fh.write("\n".join(lines)) print("已写入") return 0 if __name__ == "__main__": sys.exit(main())