cpu-cpuid: Remove xmltodict usage in parseCPU

'xmltodict' is a Python module that is not installed by default.
Replace it, so the dependencies of cpu-gather.py do not change
when both scripts are merged.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-01-04 12:30:13 +01:00 committed by Jiri Denemark
parent dc6e527b2d
commit 5868cfc490

View File

@ -4,7 +4,6 @@ import argparse
import os import os
import sys import sys
import json import json
import xmltodict
import xml.etree.ElementTree import xml.etree.ElementTree
@ -105,31 +104,19 @@ def parseQemu(path, features):
def parseCPUData(path): def parseCPUData(path):
cpuData = {} cpuData = dict()
with open(path, "rb") as f: for f in xml.etree.ElementTree.parse(path).getroot():
data = xmltodict.parse(f) if f.tag == "cpuid":
reg_list = ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]
for leaf in data["cpudata"]["cpuid"]: elif f.tag == "msr":
feature = {"type": "cpuid"} reg_list = ["index", "eax", "edx"]
feature["eax_in"] = int(leaf["@eax_in"], 0) else:
feature["ecx_in"] = int(leaf["@ecx_in"], 0) continue
for reg in ["eax", "ebx", "ecx", "edx"]:
feature[reg] = int(leaf["@" + reg], 0)
feature = {"type": f.tag}
for reg in reg_list:
feature[reg] = int(f.attrib.get(reg, "0"), 0)
addFeature(cpuData, feature) addFeature(cpuData, feature)
if "msr" in data["cpudata"]:
if not isinstance(data["cpudata"]["msr"], list):
data["cpudata"]["msr"] = [data["cpudata"]["msr"]]
for msr in data["cpudata"]["msr"]:
feature = {"type": "msr"}
feature["index"] = int(msr["@index"], 0)
feature["edx"] = int(msr["@edx"], 0)
feature["eax"] = int(msr["@eax"], 0)
addFeature(cpuData, feature)
return cpuData return cpuData