Skip to content

Commit

Permalink
q-dev: keep description as in lspci/lsusb
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Jun 12, 2024
1 parent 5d0ea72 commit 58b7872
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
23 changes: 14 additions & 9 deletions qubes/device_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,17 @@ def __str__(self):
if self.devclass == "block":
return "Block device"
if self.devclass in ("usb", "pci"):

Check warning on line 372 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L370-L372

Added lines #L370 - L372 were not covered by tests
# try subclass first as in `lspci`
result = self._load_classes(self.devclass).get(

Check warning on line 374 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L374

Added line #L374 was not covered by tests
self._interface_encoding[1:], None)
if result is None:
self._interface_encoding[1:-2] + '**', None)
if (result is None or result.lower()

Check warning on line 376 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L376

Added line #L376 was not covered by tests
in ('none', 'no subclass', 'unused', 'undefined')):
# if not, try interface
result = self._load_classes(self.devclass).get(

Check warning on line 379 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L379

Added line #L379 was not covered by tests
self._interface_encoding[1:-2] + '**', None)
if result is None:
self._interface_encoding[1:], None)
if (result is None or result.lower()

Check warning on line 381 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L381

Added line #L381 was not covered by tests
in ('none', 'no subclass', 'unused', 'undefined')):
# if not, try class
result = self._load_classes(self.devclass).get(

Check warning on line 384 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L384

Added line #L384 was not covered by tests
self._interface_encoding[1:-4] + '****', None)
if result is None:
Expand All @@ -399,21 +404,20 @@ 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():
line = line.rstrip()
if line.startswith('\t\t') \

Check warning on line 411 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L407-L411

Added lines #L407 - L411 were not covered by tests
and class_id is not None and subclass_id is not None:
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] = \

Check warning on line 414 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L413-L414

Added lines #L413 - L414 were not covered by tests
f"{class_name}: {subclass_name} ({progif_name})"
progif_name
elif line.startswith('\t') and class_id:
(subclass_id, _, subclass_name) = line[1:].split(' ', 2)

Check warning on line 417 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L416-L417

Added lines #L416 - L417 were not covered by tests
# store both prog-if specific entry and generic one
result[class_id + subclass_id + '**'] = \

Check warning on line 419 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L419

Added line #L419 was not covered by tests
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 @@ -548,7 +552,8 @@ def description(self) -> str:
else:
vendor = "unknown vendor"

Check warning on line 553 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L553

Added line #L553 was not covered by tests

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

Check warning on line 556 in qubes/device_protocol.py

View check run for this annotation

Codecov / codecov/patch

qubes/device_protocol.py#L555-L556

Added lines #L555 - L556 were not covered by tests

@property
def interfaces(self) -> List[DeviceInterface]:
Expand Down
2 changes: 1 addition & 1 deletion qubes/ext/pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def attached_devices(app):


def _device_desc(hostdev_xml):
return '{devclass}: {product} ({vendor})'.format(
return '{devclass}: {vendor} {product}'.format(
devclass=pcidev_class(hostdev_xml),
vendor=hostdev_xml.findtext('capability/vendor'),
product=hostdev_xml.findtext('capability/product'),
Expand Down
4 changes: 2 additions & 2 deletions qubes/tests/devices_pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ def test_000_unsupported_device(self):
self.assertEqual(devices[0].parent_device, None)
self.assertEqual(devices[0].libvirt_name, "pci_0000_00_14_0")
self.assertEqual(devices[0].description,
"USB controller: 9 Series Chipset Family "
"USB xHCI Controller (Intel Corporation)")
"USB controller: Intel Corporation 9 Series "
"Chipset Family USB xHCI Controller")
self.assertEqual(devices[0].self_identity, "0x8086:0x8cb1::p0c0330")

0 comments on commit 58b7872

Please sign in to comment.