If you want more of my pastes visit: https://randompaste.000webhostapp.com/index.html
--------------------------------------------------------------------------------------
view my last post at: https://bitbin.it/47LTjqoD/
--------------------------------------------------------------------------------------
#!/usr/bin/env python3
import os, subprocess, sys
from contextlib import suppress
if "-h" in sys.argv:
with suppress(subprocess.CalledProcessError):
print(subprocess.check_output(["lspci", "-h"], universal_newlines=True))
exit(0)
if "-s" in sys.argv or "-d" in sys.argv:
print("Do not use -s or -d selectors, the script does that for you.",
file=sys.stderr)
exit(1)
groups = sorted(os.scandir("/sys/kernel/iommu_groups"),
key=lambda de: int(de.name))
for i, group in enumerate(groups):
assert group.is_dir(follow_symlinks=False)
if i > 0:
print()
print(f"Group {int(group.name):2d}:")
devicespath = os.path.join(group, "devices")
devices = sorted(os.scandir(devicespath),
key=lambda de: int(de.name.translate(str.maketrans("", "", ":.")), 16))
for device in devices:
assert device.is_symlink()
assert device.is_dir(follow_symlinks=True)
lspci = subprocess.check_output(["lspci", "-s", device.name] + sys.argv[1:],
stderr=subprocess.STDOUT,
universal_newlines=True)
print(lspci.strip())
print()