# coding=utf-8 """将 JSON 模板迁移到 MySQL 总服务器,并拉取刷新本地 SQLite 缓存。""" import argparse import os import sys ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if ROOT not in sys.path: sys.path.insert(0, ROOT) from core.common_classifier import TEMPLATE_DATA_FILE, TEMPLATE_SAVE_DIR from dao.database import get_backend, init_local_engine, init_server_engine, is_server_available from dao.template_repository import TemplateRepository def main(): parser = argparse.ArgumentParser(description='迁移 JSON 到 MySQL,并刷新 SQLite 缓存') parser.add_argument('--json', default=TEMPLATE_DATA_FILE, help='JSON 模板路径') args = parser.parse_args() os.makedirs(TEMPLATE_SAVE_DIR, exist_ok=True) init_local_engine() init_server_engine() print(f"server available: {is_server_available()}") print(f"backend: {get_backend()}") repo = TemplateRepository(json_path=args.json) if is_server_available(): repo.refresh_from_server() threshold, library = repo.load_library() total = sum(len(v) for v in library.values()) print(f"categories: {len(library)}") print(f"templates: {total}") print(f"threshold: {threshold}") if __name__ == '__main__': main()