def _get_device_desc(device): """ Return human readable description of device. """ subsystem = device.get_subsystem() command = None result = None if subsystem == 'pci': (vendor_id, device_id) = device.get_property('PCI_ID').split(':') pci = PCI() result = "%s|%s" % (pci.get_vendor(vendor_id), pci.get_device(vendor_id, device_id)) elif subsystem == 'usb': vendor_id = device.get_property('ID_VENDOR_ID') usb = USB() if vendor_id: result = "%s|%s" % (usb.get_vendor(vendor_id), usb.get_device(vendor_id, device.get_property('ID_MODEL_ID'))) elif device.get_devtype() == 'usb_interface': if device.get_driver() == 'usbhid': result = 'USB HID Interface' elif device.get_driver() == 'hub': result = 'USB Hub Interface' else: result = 'USB Interface' elif device.get_devtype() == 'usb_device' and device.get_property('PRODUCT'): (vendor_id, model_id) = device.get_property('PRODUCT').split('/')[:2] # left pad it with 0 to 4 digits vendor_id = '%.4x' % int(vendor_id, 16) model_id = '%.4x' % int(model_id, 16) result = "%s|%s" % (usb.get_vendor(vendor_id), usb.get_device(vendor_id, model_id)) elif subsystem == 'block': result = device.get_property('ID_MODEL') if result: return result else: return ''
def _get_device_desc(device): """ Return human readable description of device. """ subsystem = device.get_subsystem() command = None result = None if subsystem == "pci": (vendor_id, device_id) = device.get_property("PCI_ID").split(":") pci = PCI() result = "%s|%s" % (pci.get_vendor(vendor_id), pci.get_device(vendor_id, device_id)) elif subsystem == "usb": vendor_id = device.get_property("ID_VENDOR_ID") usb = USB() if vendor_id: result = "%s|%s" % ( usb.get_vendor(vendor_id), usb.get_device(vendor_id, device.get_property("ID_MODEL_ID")), ) elif device.get_devtype() == "usb_interface": if device.get_driver() == "usbhid": result = "USB HID Interface" elif device.get_driver() == "hub": result = "USB Hub Interface" else: result = "USB Interface" elif device.get_devtype() == "usb_device" and device.get_property("PRODUCT"): (vendor_id, model_id) = device.get_property("PRODUCT").split("/")[:2] # left pad it with 0 to 4 digits vendor_id = "%.4x" % int(vendor_id, 16) model_id = "%.4x" % int(model_id, 16) result = "%s|%s" % (usb.get_vendor(vendor_id), usb.get_device(vendor_id, model_id)) elif subsystem == "block": result = device.get_property("ID_MODEL") if result: return result else: return ""
#!/usr/bin/python from hwdata import PCI, USB # for obtaining real id of your devices you can use package python-gudev pci_vendor_id = '0e11' pci_device_id = 'b01e' usb_vendor_id = '03f0' usb_device_id = '1f12' pci = PCI() print("Vendor: %s" % pci.get_vendor(pci_vendor_id)) print("Device: %s" % pci.get_device(pci_vendor_id, pci_device_id)) usb = USB() print("Vendor: %s" % usb.get_vendor(usb_vendor_id)) print("Device: %s" % usb.get_device(usb_vendor_id, usb_device_id))