kellyjonbrazil / jc

CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
MIT License
7.82k stars 202 forks source link

lspci strips trailing digit on bus ID #568

Closed stellarpower closed 4 months ago

stellarpower commented 4 months ago
❯ lspci | grep 3090
01:00.0 VGA compatible controller: NVIDIA Corporation GA102 [GeForce RTX 3090] (rev a1)

❯ lspci | grep 3090 | jc --lspci
[{"01:00.":"VGA compatible controller: NVIDIA Corporation GA102 [GeForce RTX 3090] (rev a1)"}]

I wanted to use this as a quick way to get the bus ID without parsing text - notice how the object key is 01:00. and not 01:00.0. I used grep to make less noisy output but the same happens with all devices.

Thanks!

stellarpower commented 4 months ago

Looks related to #554, but not sure if that fixes both issues or not as it seemed a distinct problem.

kellyjonbrazil commented 4 months ago

Hi there! It doesn't look like this output is supported by the lspci parser. The parser should be used with at least the -mmv arguments. The JSON output will be an array of objects with consistently named keys. The keys will not be named by the bus-id:

    $ lspci -nnmmv | jc --lspci -p
    [
      {
        "slot": "ff:02:05.0",
        "domain": "ff",
        "domain_int": 255,
        "bus": "02",
        "bus_int": 2,
        "dev": "05",
        "dev_int": 5,
        "function": "0",
        "function_int": 0,
        "class": "SATA controller",
        "class_id": "0106",
        "class_id_int": 262,
        "vendor": "VMware",
        "vendor_id": "15ad",
        "vendor_id_int": 5549,
        "device": "SATA AHCI controller",
        "device_id": "07e0",
        "device_id_int": 2016,
        "svendor": "VMware",
        "svendor_id": "15ad",
        "svendor_id_int": 5549,
        "sdevice": "SATA AHCI controller",
        "sdevice_id": "07e0",
        "sdevice_id_int": 2016,
        "physlot": "37",
        "progif": "01",
        "progif_int": 1
      },
      ...
    ]

Please see jc --help --lspci for mor information. Thanks!

stellarpower commented 4 months ago

Ah okay, thanks. I did see that, but when I looked because I didn't put the grep in the middle or because this filtered out all the other information when using those flags, the slot numbers seemed wildly different from the entries under /sys/bus/pci/devices, and the vendor codes etc. weren't much use to me. So I figured the slot number must be something different form the logical address (these all start with 0 in the sysfs directory too, so I was looking for that). I must have misscanned them when looking through the output as there are obviously many devices it returns back.

Guess it'd be nice to support (or throw an exception if it's not really parseable), but this one's on me so feel free to close.

Thanks!