#!/usr/bin/env python3 """Apply an external theme's whitelisted SVG fill/stroke bindings, locally.""" from __future__ import annotations import argparse import json from pathlib import Path import re import sys import xml.etree.ElementTree as ET import template_ref as ref from native_export import boundary_file, regular def paint(manifest_path: Path, theme_id: str, role: str, output: Path): manifest_path = regular(manifest_path, "manifest") manifest = ref.load_manifest(manifest_path) ref.require(manifest["schema_version"] == 2, "Paint application requires manifest schema 2") ref.require(theme_id in manifest["themes"], "Unknown theme") _, theme = ref.load_theme(manifest_path.parent, manifest["themes"][theme_id], theme_id) asset = theme["assets"].get(role) ref.require(asset is not None and "paint_contract" in asset, "Asset needs an explicit SVG paint contract") root_path = manifest_path.parent source = boundary_file(root_path, asset["path"], "SVG asset") contract_path = boundary_file(root_path, asset["paint_contract"], "paint contract") contract = ref.read_json(contract_path, (1,)) text = source.read_text(encoding="utf-8") ref.require(not re.search(r"