From 7e21cf58ea4ad2c8470f5025eb467be8fe94521f Mon Sep 17 00:00:00 2001 From: Filip Strajnar Date: Sun, 27 Oct 2024 10:14:34 +0100 Subject: [PATCH] Driver name is now responsibility of PciDevice class instead of a separate function. --- src/pci_passthrough_assist/pci.py | 7 ------- src/pci_passthrough_assist/pci_device.py | 9 ++++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/pci_passthrough_assist/pci.py b/src/pci_passthrough_assist/pci.py index 259f8e0..68b8780 100644 --- a/src/pci_passthrough_assist/pci.py +++ b/src/pci_passthrough_assist/pci.py @@ -1,5 +1,4 @@ from os import listdir -from os.path import realpath, basename def all_pci_device_ids() -> list[str]: @@ -8,9 +7,3 @@ def all_pci_device_ids() -> list[str]: def all_pci_driver_ids() -> list[str]: return listdir("/sys/bus/pci/drivers") - - -def driver_of_pci_device(pci_device_id: str) -> str: - driver_directory: str = realpath( - f"/sys/bus/pci/devices/{pci_device_id}/driver") - return basename(driver_directory) diff --git a/src/pci_passthrough_assist/pci_device.py b/src/pci_passthrough_assist/pci_device.py index e614f82..cdf841a 100644 --- a/src/pci_passthrough_assist/pci_device.py +++ b/src/pci_passthrough_assist/pci_device.py @@ -1,5 +1,4 @@ -from pci_passthrough_assist.pci import driver_of_pci_device -from os.path import exists +from os.path import exists, realpath, basename from os import listdir @@ -10,7 +9,11 @@ class PciDevice: self.device_id = device_id def driver_name(self) -> str: - return driver_of_pci_device(self.device_id) + pci_driver_path = f"/sys/bus/pci/devices/{self.device_id}/driver" + if not exists(pci_driver_path): + return "NO-DRIVER-BOUND" + driver_directory: str = realpath(pci_driver_path) + return basename(driver_directory) def is_vga(self) -> bool: return exists(f"/sys/bus/pci/devices/{self.device_id}/boot_vga")