46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Prebuild persistent indexes for the KiCad v10 library cache.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
|
|
SCRIPT_DIR = Path(__file__).resolve().parent
|
|
if str(SCRIPT_DIR) not in sys.path:
|
|
sys.path.insert(0, str(SCRIPT_DIR))
|
|
|
|
from mcp_servers.kicad_text import ( # type: ignore
|
|
clear_container_indexes,
|
|
footprint_index_path,
|
|
prewarm_container_indexes,
|
|
)
|
|
from mcp_servers.kicad_symbol_sqlite import build_symbol_sqlite_index, symbol_sqlite_index_path # type: ignore
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Prebuild KiCad v10 symbol and footprint indexes")
|
|
parser.add_argument("--refresh", action="store_true", help="Clear existing indexes before rebuilding")
|
|
args = parser.parse_args()
|
|
|
|
if args.refresh:
|
|
clear_container_indexes()
|
|
|
|
symbol_summary = build_symbol_sqlite_index(refresh=False)
|
|
summary = prewarm_container_indexes(refresh=False)
|
|
summary["symbol_index"] = str(symbol_sqlite_index_path())
|
|
summary["symbol_components"] = symbol_summary.get("symbol_components", summary.get("symbol_components", 0))
|
|
summary["symbol_libraries"] = symbol_summary.get("symbol_libraries", summary.get("symbol_libraries", 0))
|
|
summary["footprint_index"] = str(footprint_index_path())
|
|
print(json.dumps(summary, ensure_ascii=True))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|