MCPcopy Create free account
hub / github.com/RASAAS/docmcp-knowledge / sync_page

Function sync_page

scripts/sync_zh_fulltext.py:28–52  ·  view source on GitHub ↗
(docs_path: Path, zh_fulltext_path: Path, dry_run: bool = False)

Source from the content-addressed store, hash-verified

26
27
28def sync_page(docs_path: Path, zh_fulltext_path: Path, dry_run: bool = False) -> bool:
29 if not docs_path.exists():
30 return False
31 if not zh_fulltext_path.exists():
32 return False
33
34 page_text = docs_path.read_text(encoding="utf-8")
35 marker_pos = page_text.find(FULLTEXT_MARKER)
36 if marker_pos == -1:
37 return False
38
39 header = page_text[:marker_pos + len(FULLTEXT_MARKER)]
40 zh_content = zh_fulltext_path.read_text(encoding="utf-8")
41
42 new_page = header + "\n\n---\n\n## \u5b98\u65b9\u6587\u4ef6\u5168\u6587\n\n" + zh_content + "\n"
43
44 if dry_run:
45 old_lines = page_text.count("\n")
46 new_lines = new_page.count("\n")
47 print(f" [DRY-RUN] {docs_path.name}: {old_lines} -> {new_lines} lines")
48 return True
49
50 docs_path.write_text(new_page, encoding="utf-8")
51 print(f" [OK] {docs_path.name} ({len(new_page)} bytes)")
52 return True
53
54
55def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected