in pcicrawler/cli.py [0:0]
def print_tree_level(devgroups, indent, roots): # noqa: C901
spc = indent
n = 0
sfx = ' \u2502 '
dmislots = get_dmidecode_pci_slots()
for dev in roots:
n += 1
last = n == len(roots)
addr = dev.device_name
dispaddr = maybe_shorten_pci_addr(addr)
exptype = dev.express_type
explink = dev.express_link
slot = dev.express_slot
dmidev = dmislots.get(addr)
if last and spc:
indent = indent[:-3] + ' '
spc = spc[:-3] + ' \u2514\u2500'
elif spc:
spc = spc[:-3] + ' \u251C\u2500'
treeline = f'{spc}{click.style(dispaddr, fg="yellow")} '
if exptype:
treeline += click.style(str(exptype), fg="red")
else:
treeline += click.style('PCI', underline=True)
if dmidev:
treeline += ', "{}"'.format(dmidev["designation"])
if slot:
treeline += f', slot {click.style(str(slot.slot), fg="blue")}'
if slot.presence:
treeline += ', ' + click.style('device present', fg="blue")
if slot.power is not None:
power = 'On' if slot.power else 'Off'
color = 'green' if slot.power else 'red'
treeline += ', power: ' + click.style(power, fg=color)
if slot.attn_led != 'unsupported' and slot.attn_led != 'off':
treeline += ', attn: ' + click.style(slot.attn_led, fg='red')
if explink:
if exptype in {'downstream_port', 'root_port'} and \
explink.cur_width != 0:
treeline += ', speed ' + \
click.style(explink.cur_speed, fg="blue") + \
', width ' + \
click.style(f'x{explink.cur_width}', fg="blue")
# if cur_width == 0 there's no link at all target_speed is None if
# device doesn't provide it and ports will report < target speed if
# their downstream endpoint isn't capable of its target speed, so
# only check endpoints.
if explink.target_speed and \
explink.cur_speed != explink.target_speed and \
exptype == 'endpoint' and \
explink.cur_width != 0:
treeline += ', current speed ' + \
click.style(explink.cur_speed, fg="blue") + \
' target speed ' + \
click.style(explink.target_speed, fg="blue")
if exptype in {'endpoint',
'upstream_port',
'root_complex_endpoint'} or exptype is None:
treeline += ', ' + click.style(dev.name, fg="green")
click.echo(treeline)
if addr in devgroups:
print_tree_level(devgroups, indent + sfx, devgroups[addr])