From 5ad06e933a829dd4ea10a0d29c89a9a82e63d657 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Thu, 29 Jul 2021 14:27:16 +0800 Subject: [PATCH] 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 --- misc/config_tools/board_inspector/extractors/80-lookup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/misc/config_tools/board_inspector/extractors/80-lookup.py b/misc/config_tools/board_inspector/extractors/80-lookup.py index 90549255e..8449b7a89 100644 --- a/misc/config_tools/board_inspector/extractors/80-lookup.py +++ b/misc/config_tools/board_inspector/extractors/80-lookup.py @@ -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")