Files
dcalc/scripts/remove_character_remove_lines.py
2026-07-13 01:35:40 +08:00

39 lines
1.2 KiB
Python

"""Batch-remove every line containing ``# REMOVE`` from character modules."""
from __future__ import annotations
import argparse
import ast
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
CHARACTER_ROOT = ROOT / "backend" / "core" / "character"
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--check", action="store_true", help="report only; do not write")
args = parser.parse_args()
files = removed_total = 0
for path in sorted(CHARACTER_ROOT.rglob("*.py")):
source = path.read_text(encoding="utf-8")
lines = source.splitlines(keepends=True)
kept = [line for line in lines if "# REMOVE" not in line]
removed = len(lines) - len(kept)
if not removed:
continue
output = "".join(kept)
ast.parse(output, filename=str(path))
files += 1
removed_total += removed
print(f"{'CHECK' if args.check else 'WRITE'} {path.relative_to(ROOT)}: {removed}")
if not args.check:
path.write_text(output, encoding="utf-8", newline="\n")
print(f"TOTAL files={files} lines={removed_total}")
return 0
if __name__ == "__main__":
raise SystemExit(main())