From 66e5204cc394b1e76b2ccc8f15576285fd95111a Mon Sep 17 00:00:00 2001 From: Jonathan Miller <230051081+jmiller-moko@users.noreply.github.com> Date: Sat, 3 Jan 2026 13:21:09 -0600 Subject: [PATCH] Update xml_wellformed.sh --- scripts/validate/xml_wellformed.sh | 59 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/scripts/validate/xml_wellformed.sh b/scripts/validate/xml_wellformed.sh index 0e795c7..2c97541 100644 --- a/scripts/validate/xml_wellformed.sh +++ b/scripts/validate/xml_wellformed.sh @@ -32,32 +32,22 @@ set -euo pipefail SRC_DIR="${SRC_DIR:-src}" -json_escape() { python3 - <<'PY' "$1"; import json,sys; print(json.dumps(sys.argv[1])); PY; } - -emit_ok() { - local extra="${1:-}" - if [ -n "${extra}" ]; then - printf '{"status":"ok",%s} -' "${extra}" - else - printf '{"status":"ok"} -' - fi +json_escape() { + python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$1" } -emit_fail() { - local msg="$1" - local extra="${2:-}" - if [ -n "${extra}" ]; then - printf '{"status":"fail","error":%s,%s} -' "$(json_escape "${msg}")" "${extra}" - else - printf '{"status":"fail","error":%s} -' "$(json_escape "${msg}")" - fi +fail() { + local msg="$1" + local extra="${2:-}" + if [ -n "${extra}" ]; then + printf '{"status":"fail","error":%s,%s}\n' "$(json_escape "${msg}")" "${extra}" + else + printf '{"status":"fail","error":%s}\n' "$(json_escape "${msg}")" + fi + exit 1 } -[ -d "${SRC_DIR}" ] || { emit_fail "src directory missing" "\"src_dir\":$(json_escape "${SRC_DIR}")"; exit 1; } +[ -d "${SRC_DIR}" ] || fail "src directory missing" "\"src_dir\":$(json_escape "${SRC_DIR}")" python3 - <<'PY' "${SRC_DIR}" import json @@ -70,16 +60,27 @@ xml_files = sorted([p for p in src.rglob('*.xml') if p.is_file()]) bad = [] for p in xml_files: - try: - ET.parse(p) - except Exception as e: - bad.append({"path": str(p), "error": str(e)}) + try: + ET.parse(p) + except Exception as e: + bad.append({"path": str(p), "error": str(e)}) if bad: - print(json.dumps({"status":"fail","error":"XML parse failed","bad_count":len(bad),"bad":bad[:25]}, ensure_ascii=False)) - sys.exit(1) + print(json.dumps({ + "status": "fail", + "error": "XML parse failed", + "src_dir": str(src), + "xml_count": len(xml_files), + "bad_count": len(bad), + "bad": bad[:25], + }, ensure_ascii=False)) + sys.exit(1) -print(json.dumps({"status":"ok","src_dir":str(src),"xml_count":len(xml_files)}, ensure_ascii=False)) +print(json.dumps({ + "status": "ok", + "src_dir": str(src), + "xml_count": len(xml_files), +}, ensure_ascii=False)) PY echo "xml_wellformed: ok"