Update xml_wellformed.sh

This commit is contained in:
2026-01-03 13:21:09 -06:00
parent 387941e08c
commit 66e5204cc3

View File

@@ -32,32 +32,22 @@ set -euo pipefail
SRC_DIR="${SRC_DIR:-src}" SRC_DIR="${SRC_DIR:-src}"
json_escape() { python3 - <<'PY' "$1"; import json,sys; print(json.dumps(sys.argv[1])); PY; } json_escape() {
python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$1"
emit_ok() {
local extra="${1:-}"
if [ -n "${extra}" ]; then
printf '{"status":"ok",%s}
' "${extra}"
else
printf '{"status":"ok"}
'
fi
} }
emit_fail() { fail() {
local msg="$1" local msg="$1"
local extra="${2:-}" local extra="${2:-}"
if [ -n "${extra}" ]; then if [ -n "${extra}" ]; then
printf '{"status":"fail","error":%s,%s} printf '{"status":"fail","error":%s,%s}\n' "$(json_escape "${msg}")" "${extra}"
' "$(json_escape "${msg}")" "${extra}"
else else
printf '{"status":"fail","error":%s} printf '{"status":"fail","error":%s}\n' "$(json_escape "${msg}")"
' "$(json_escape "${msg}")"
fi 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}" python3 - <<'PY' "${SRC_DIR}"
import json import json
@@ -76,10 +66,21 @@ for p in xml_files:
bad.append({"path": str(p), "error": str(e)}) bad.append({"path": str(p), "error": str(e)})
if bad: if bad:
print(json.dumps({"status":"fail","error":"XML parse failed","bad_count":len(bad),"bad":bad[:25]}, ensure_ascii=False)) 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) 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 PY
echo "xml_wellformed: ok" echo "xml_wellformed: ok"