Skip to content

Commit

Permalink
q-dev: update device protocol v4
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed May 26, 2024
1 parent 9d3abb2 commit e11de7f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions qubesadmin/device_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,17 @@ def __str__(self):
if self.devclass == "block":
return "Block device"
if self.devclass in ("usb", "pci"):
# try subclass first as in `lspci`
result = self._load_classes(self.devclass).get(
self._interface_encoding[1:], None)
if result is None:
self._interface_encoding[1:-2] + '**', None)
if (result is None or result.lower()
in ('none', 'no subclass', 'unused', 'undefined')):
# if not, try interface
result = self._load_classes(self.devclass).get(
self._interface_encoding[1:-2] + '**', None)
if result is None:
self._interface_encoding[1:], None)
if (result is None or result.lower()
in ('none', 'no subclass', 'unused', 'undefined')):
# if not, try class
result = self._load_classes(self.devclass).get(
self._interface_encoding[1:-4] + '****', None)
if result is None:
Expand All @@ -421,7 +426,6 @@ def _load_classes(bus: str):
encoding='utf-8', errors='ignore') as pciids:
# for `class_name` and `subclass_name`
# pylint: disable=used-before-assignment
# pylint: disable=possibly-used-before-assignment
class_id = None
subclass_id = None
for line in pciids.readlines():
Expand All @@ -430,12 +434,12 @@ def _load_classes(bus: str):
and class_id is not None and subclass_id is not None:
(progif_id, _, progif_name) = line[2:].split(' ', 2)
result[class_id + subclass_id + progif_id] = \
f"{class_name}: {subclass_name} ({progif_name})"
progif_name
elif line.startswith('\t') and class_id:
(subclass_id, _, subclass_name) = line[1:].split(' ', 2)
# store both prog-if specific entry and generic one
result[class_id + subclass_id + '**'] = \
f"{class_name}: {subclass_name}"
subclass_name
elif line.startswith('C '):
(_, class_id, _, class_name) = line.split(' ', 3)
result[class_id + '****'] = class_name
Expand Down Expand Up @@ -570,7 +574,8 @@ def description(self) -> str:
else:
vendor = "unknown vendor"

return f"{prod} ({vendor})"
main_interface = str(self.interfaces[0])
return f"{main_interface}: {vendor} {prod}"

@property
def interfaces(self) -> List[DeviceInterface]:
Expand Down

0 comments on commit e11de7f

Please sign in to comment.