Peach: Local-first video metadata scraper and media manager.
fix(scripts): 重名冲突只挡自己那一行,不再扣住整批改名
longmeidaoccf6bbb5f8e0
diff --git a/scripts/localize_performer_names.py b/scripts/localize_performer_names.pyindex 1c759b146..680b20ced 100644--- a/scripts/localize_performer_names.py+++ b/scripts/localize_performer_names.py@@ -437,12 +437,23 @@ def _rewrite_actor_tags(return rewritten+def report_conflicts(rows: list[dict[str, object]]) -> int:+ """逐条打出重名冲突:它们靠被人看见来解决,不靠把整批改名扣在门外。"""+ stuck = [row for row in rows if row["action"] == "conflict"]+ for row in stuck:+ print(f" 重名待裁决:{row['entity_id']} {row['current_name']} -> "+ f"{row['target_name']}({row['resolution']})")+ return len(stuck)++def apply_rows(connection: sqlite3.Connection, rows: list[dict[str, object]], revision: str,) -> dict[str, int]:- if any(row["action"] == "conflict" for row in rows):- raise RuntimeError("复核计划仍有 target-name-conflict,拒绝写入")counts = Counter()+ # 重名冲突只挡住它自己那一行:下面的写入循环本来就跳过 conflict,整批拒绝扣住的+ # 是另外九十条毫无关系的改名——一个等人授权的同人合并不该冻住整轮本地化。跳过的+ # 行照样计数、照样让退出码非零,不会悄悄消失。+ counts["conflicts_skipped"] = sum(1 for row in rows if row["action"] == "conflict")source = f"{ALIAS_SOURCE_PREFIX}@{revision[:12]}"by_id = {int(row["entity_id"]): row for row in rows}@@ -552,7 +563,7 @@ def run(args: argparse.Namespace) -> int:print(" 动作分布:", dict(Counter(str(row["action"]) for row in rows)))if not args.apply:print(" 未写 ledger(加 --apply --backup 才写)")- return 1 if any(row["action"] == "conflict" for row in rows) else 0+ return 1 if report_conflicts(rows) else 0print(f" 已备份到 {args.backup}")before = counts_of(connection, EXTRA_COUNTS)@@ -564,7 +575,8 @@ def run(args: argparse.Namespace) -> int:for key in before:print(f" {key}: {before[key]} -> {after[key]}")print(f" integrity_check={integrity};foreign_key_check={foreign_keys}")- return 1 if integrity != "ok" or foreign_keys else 0+ stuck = report_conflicts(rows)+ return 1 if integrity != "ok" or foreign_keys or stuck else 0finally:connection.close()diff --git a/tests/test_performer_localization.py b/tests/test_performer_localization.pyindex 8347de59c..2f23ce1b4 100644--- a/tests/test_performer_localization.py+++ b/tests/test_performer_localization.py@@ -8,7 +8,7 @@ from pathlib import Pathfrom peach.migrations import upgradefrom scripts.localize_performer_names import (KANJI_ALIAS_SOURCE, apply_rows, collect, main, read_identity_review, read_mapping,- resolve_sai, simplify_kanji, strip_zero_width,+ report_conflicts, resolve_sai, simplify_kanji, strip_zero_width,)ROOT = Path(__file__).resolve().parents[1]@@ -213,8 +213,14 @@ class PerformerLocalizationTests(unittest.TestCase):self.con, [], read_identity_review(self.review), "kanji-only")}self.assertEqual(rows[16]["action"], "conflict")self.assertIn("target-name-conflict", rows[16]["resolution"])- with self.assertRaises(RuntimeError):- apply_rows(self.con, list(rows.values()), "kanji-only")+ # 待裁决的那一行只挡住自己:同一批里其它人的字形照样归一,+ # 否则库里一处未合并的同人就能无限期冻住全部改名。+ counts = apply_rows(self.con, list(rows.values()), "kanji-only")+ self.assertEqual(counts["conflicts_skipped"], 1)+ names = dict(self.con.execute("SELECT id,canonical_name FROM entity"))+ self.assertEqual(names[16], "斎藤満里奈")+ self.assertEqual(names[17], "野野宫兰")+ self.assertEqual(report_conflicts(list(rows.values())), 1)def test_mapping_xml_is_optional_and_its_revision_is_not(self):"""那份 XML 不在仓库里,也可能已经不在这台机器上;缺了它字形归一仍要能跑。"""