f.write("</cpudata>\n")
+def output_json(data, filename):
+ replies = list()
+ for reply in data["model"]:
+ if "QMP" in reply:
+ continue
+ if "timestamp" in reply:
+ continue
+ if "return" in reply and not reply["return"]:
+ continue
+ replies.append(reply)
+
+ if not replies:
+ return
+
+ if "model-expansion" not in [reply.get("id") for reply in replies]:
+ exit(
+ "Error: Missing query-cpu-model-expansion reply in "
+ "{}".format(filename))
+
+ print(filename)
+ with open(filename, "wt") as f:
+ for reply in replies:
+ if reply is not replies[0]:
+ f.write("\n")
+ json.dump(reply, f, indent=2)
+ f.write("\n")
+
+
def parse(args):
data = json.load(sys.stdin)
filename = parse_filename(data)
filename_xml = "{}.xml".format(filename)
+ filename_json = "{}.json".format(filename)
output_xml(data, filename_xml)
+ output_json(data, filename_json)
os.environ["CPU_GATHER_PY"] = "true"
os.environ["model"] = data["name"]
data=`cat`
-json()
-{
- first=true
- sed -ne '/{"QMP".*/d;
- /{"return": {}}/d;
- /{"timestamp":.*/d;
- /^{/p' <<<"$data" | \
- while read; do
- $first || echo
- first=false
- $(dirname $0)/cpu-reformat.py <<<"$REPLY"
- done
-}
-
-json <<<"$data" >$fname.json
if [[ -s $fname.json ]]; then
- echo $fname.json
if ! grep -q model-expansion $fname.json; then
echo "Missing query-cpu-model-expansion reply in $name.json" >&2
exit 1
+++ /dev/null
-#!/usr/bin/env python3
-
-import sys
-import json
-
-dec = json.JSONDecoder()
-data, pos = dec.raw_decode(sys.stdin.read())
-json.dump(data, sys.stdout, indent=2, separators=(',', ': '))
-print("")