board_inspector: also try /usr/share/pci.ids.gz for PCI ID lookup

/usr/share/pci.ids.gz is another typical path to the pci.ids file of the
lspci tool which is used in Yocto-based systems. This patch adds this path
as another candidate when searching for pci.ids. The builtin gzip module is
used to open this file.

Tracked-On: #6287
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2021-07-29 14:27:16 +08:00 committed by wenlingz
parent 1e092a89d6
commit 5ad06e933a
1 changed files with 7 additions and 1 deletions

View File

@ -5,12 +5,14 @@
import os
import logging
import gzip
from extractors.helpers import get_node
PCI_IDS_PATHS = [
"/usr/share/misc/pci.ids",
"/usr/share/hwdata/pci.ids",
"/usr/share/pci.ids.gz",
]
class PCI_IDs:
@ -22,6 +24,9 @@ class PCI_IDs:
class_id = None
for line in f.readlines():
if isinstance(line, (bytes, bytearray)):
line = line.decode()
line = line.strip("\n")
if line == "" or line.startswith("#"):
continue
@ -106,7 +111,8 @@ def lookup_pci_devices(board_etree):
pci_id_path = path
if pci_id_path:
with open(pci_id_path, "r") as f:
opener = gzip.open if pci_id_path.endswith(".gz") else open
with opener(pci_id_path, "r") as f:
ids = PCI_IDs(f)
devices = board_etree.xpath("//device")