Spaces:
Sleeping
Sleeping
File size: 1,292 Bytes
55d9355 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | """Sincroniza o catálogo versionado da MESA sem importar seu backend."""
import ast
import json
from pathlib import Path
import sys
root = Path(__file__).resolve().parents[1]
mesa = Path(sys.argv[1]) if len(sys.argv) > 1 else root.parent / "mesa-frame"
source = mesa / "backend/app/core/redutores_territoriais.py"
tree = ast.parse(source.read_text(encoding="utf-8"))
version = next(ast.literal_eval(node.value) for node in tree.body
if isinstance(node, ast.Assign)
and any(isinstance(target, ast.Name) and target.id == "VERSAO_REGRAS_REDUTORES" for target in node.targets))
catalog = next(node.value for node in tree.body if isinstance(node, ast.AnnAssign)
and isinstance(node.target, ast.Name) and node.target.id == "CATALOGO_REDUTORES")
class ResolveVersion(ast.NodeTransformer):
def visit_Name(self, node):
return ast.Constant(value=version) if node.id == "VERSAO_REGRAS_REDUTORES" else node
data = {"origem": "mesa-frame/backend/app/core/redutores_territoriais.py",
"catalogo": ast.literal_eval(ResolveVersion().visit(catalog))}
destination = root / "config/mesa_redutores.json"
destination.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
print(f"Catálogo sincronizado: {version}")
|