3 from pypciscan import get_devices
6 """ This is a replacement to the version in pypciscan library for 3.3 and lower bootcds
7 that will help maintain backward compatibility. This version has limitations wrt accuracy
8 that the library does not. In particular it is limited to the output of
9 lspci and 'forces' all devices to appear on the '0000' domain, rather than
10 where they actually are."""
13 pci_cmd = os.popen("""/sbin/lspci -nvm | sed -e 's/\t/ /g' -e 's/ Class //' -e 's/^/"/' -e 's/$/"/' -e 's/$/,/' -e 's/^"",$/],[/'""", 'r')
14 pci_str = "[" + pci_cmd.read() + "]"
15 pci_list = eval(pci_str)
18 # convert each entry into a dict. and convert strings to ints.
24 # There are two 'device' fields in the output. Append
25 # 'addr' for the bus address, identified by the extra ':'.
27 key = s[0].lower() + "addr"
31 value = int(s[1].strip(), 16)
35 pci_devlist.append(rec)
38 # convert this list of devices into the format expected by the
39 # consumer of get_devices()
40 for dev in pci_devlist:
41 if 'device' not in dev:
44 if 'sdevice' in dev: subdev = dev['sdevice']
45 else: subdev = 0xffffffffL
47 if 'svendor' in dev: subvend = dev['svendor']
48 else: subvend = 0xffffffffL
50 key = "0000:%s" % dev['deviceaddr']
51 value = (dev['vendor'], dev['device'], subvend, subdev, dev['class'] << 8)