4 """ This is a replacement to the pypciscan library."""
7 pci_cmd = os.popen("""/sbin/lspci -nvm | sed -e 's/\t/ /g' -e 's/^/"/' -e 's/$/"/' -e 's/$/,/' -e 's/^"",$/],[/'""", 'r')
8 pci_str = "[" + pci_cmd.read() + "]"
9 pci_list = eval(pci_str)
12 # convert each entry into a dict. and convert strings to ints.
18 # There are two 'device' fields in the output. Append
19 # 'addr' for the bus address, identified by the extra ':'.
21 key = s[0].lower() + "addr"
25 value = int(s[1].strip(), 16)
29 pci_devlist.append(rec)
32 # convert this list of devices into the format expected by the
33 # consumer of get_devices()
34 for dev in pci_devlist:
35 if 'deviceaddr' not in dev:
38 if 'sdevice' in dev: subdev = dev['sdevice']
39 else: subdev = 0xffffffffL
41 if 'svendor' in dev: subvend = dev['svendor']
42 else: subvend = 0xffffffffL
44 if 'progif' in dev: progif = dev['progif']
47 value = (dev['vendor'], dev['device'], subvend, subdev, dev['class'] << 8 | progif)
48 ret[dev['deviceaddr']] = value