cpu-cpuid: Remove xmltodict usage in parseMap

'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:12 +01:00 committed by Jiri Denemark
parent b53eb0db35
commit dc6e527b2d

View File

@ -5,6 +5,7 @@ import os
import sys import sys
import json import json
import xmltodict import xmltodict
import xml.etree.ElementTree
def checkCPUIDFeature(cpuData, feature): def checkCPUIDFeature(cpuData, feature):
@ -132,37 +133,23 @@ def parseCPUData(path):
return cpuData return cpuData
def parseMapFeature(fType, data):
ret = {"type": fType}
if fType == "cpuid":
fields = ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]
elif fType == "msr":
fields = ["index", "edx", "eax"]
for field in fields:
attr = "@%s" % field
if attr in data:
ret[field] = int(data[attr], 0)
else:
ret[field] = 0
return ret
def parseMap(): def parseMap():
path = os.path.dirname(sys.argv[0]) path = os.path.dirname(sys.argv[0])
path = os.path.join(path, "..", "..", "src", "cpu_map", "x86_features.xml") path = os.path.join(path, "..", "..", "src", "cpu_map", "x86_features.xml")
with open(path, "rb") as f:
data = xmltodict.parse(f)
cpuMap = {} cpuMap = dict()
for feature in data["cpus"]["feature"]: for f in xml.etree.ElementTree.parse(path).getroot().iter("feature"):
for fType in ["cpuid", "msr"]: if f[0].tag == "cpuid":
if fType not in feature: reg_list = ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]
continue elif f[0].tag == "msr":
cpuMap[feature["@name"]] = parseMapFeature(fType, feature[fType]) reg_list = ["index", "eax", "edx"]
else:
continue
feature = {"type": f[0].tag}
for reg in reg_list:
feature[reg] = int(f[0].attrib.get(reg, "0"), 0)
cpuMap[f.attrib["name"]] = feature
return cpuMap return cpuMap