Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[parsers /pci_ids.py] Only last [subvendor][subdevice] got loaded into result when multiple subdevices having the same subvendor id #558

Open
ssiuhk opened this issue Apr 10, 2024 · 2 comments
Labels
bug Something isn't working ready-to-ship

Comments

@ssiuhk
Copy link

ssiuhk commented Apr 10, 2024

Description
It was found that when parsing pci_ids, only the last subvendor/subdevice data is available in parsed data when there are multiple subdevices sharing the same subvendor id.

Steps to Reproduce the behavior

Python 3.9.18 (main, Jan 24 2024, 00:00:00)
[GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jc
>>> with open('/usr/share/hwdata/pci.ids', 'r', encoding='utf-8') as pcifp:
...     pci_data_str = pcifp.read()
...
>>> pci_ids = jc.parse('pci_ids', pci_data_str)
>>> from pprint import pprint
>>> pprint(pci_ids['vendors'].get("_168c", {}).get("_0012"))
{'_1186': {'_3a05': {'subsystem_name': 'AirPro DWL-AB520 Multimode Wireless '
                                       'PCI Adapter'}},
 '_126c': {'_8031': {'subsystem_name': '2201 Mobile Adapter'}},
 '_1385': {'_4400': {'subsystem_name': 'WAB501 802.11ab Wireless CardBus '
                                       'Card'}},
 '_1b47': {'_aa00': {'subsystem_name': '8460 802.11ab Wireless CardBus '
                                       'Adapter'}},
 'device_name': 'AR5211 Wireless Network Adapter [AR5001X 802.11ab]'}

===============================================================

168c  Qualcomm Atheros
        0012  AR5211 Wireless Network Adapter [AR5001X 802.11ab]
                1186 3a03  AirPro DWL-A650 Wireless Cardbus Adapter (rev.B)
                1186 3a04  AirPro DWL-AB650 Multimode Wireless Cardbus Adapter
                1186 3a05  AirPro DWL-AB520 Multimode Wireless PCI Adapter
                126c 8031  2201 Mobile Adapter
                1385 4400  WAB501 802.11ab Wireless CardBus Card
                1b47 aa00  8460 802.11ab Wireless CardBus Adapter

Expected behavior
The output of pprint(pci_ids['vendors'].get("_168c", {}).get("_0012")) should be like

{'_1186': {'_3a03': {'subsystem_name': 'AirPro DWL-A650 Wireless Cardbus '
                                       'Adapter (rev.B)'},
           '_3a04': {'subsystem_name': 'AirPro DWL-AB650 Multimode Wireless '
                                       'Cardbus Adapter'},
           '_3a05': {'subsystem_name': 'AirPro DWL-AB520 Multimode Wireless '
                                       'PCI Adapter'}},
 '_126c': {'_8031': {'subsystem_name': '2201 Mobile Adapter'}},
 '_1385': {'_4400': {'subsystem_name': 'WAB501 802.11ab Wireless CardBus '
                                       'Card'}},
 '_1b47': {'_aa00': {'subsystem_name': '8460 802.11ab Wireless CardBus '
                                       'Adapter'}},
 'device_name': 'AR5211 Wireless Network Adapter [AR5001X 802.11ab]'}

Versions Report

(myenv) [ssiu@myhost tmp.hAUtVFADtV]$ pip list
Package          Version
---------------- -------
jc               1.25.2  <=======
pip              24.0
Pygments         2.17.2
ruamel.yaml      0.18.6
ruamel.yaml.clib 0.2.8
setuptools       53.0.0
xmltodict        0.13.0

Python 3.9.18 (main, Jan 24 2024, 00:00:00)
[GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] on linux
ssiuhk added a commit to ssiuhk/jc that referenced this issue Apr 10, 2024
… dict creation

- Updated jc/parsers/pci_ids.py adding a check to see if the subvendor dict is already created

Signed-off-by: Sam SIU <23556929+ssiuhk@users.noreply.github.com>
@kellyjonbrazil
Copy link
Owner

Thanks for reporting this and for the fix! I'll run it through some tests and update the docs.

@kellyjonbrazil kellyjonbrazil added the bug Something isn't working label Apr 10, 2024
ssiuhk added a commit to ssiuhk/jc that referenced this issue Apr 10, 2024
… dict creation

- Updated jc/parsers/pci_ids.py adding a check to see if the subvendor dict is already created
- Updated test fixture

Signed-off-by: Sam SIU <23556929+ssiuhk@users.noreply.github.com>
kellyjonbrazil added a commit that referenced this issue Apr 28, 2024
…#559)

- Updated jc/parsers/pci_ids.py adding a check to see if the subvendor dict is already created
- Updated test fixture

Signed-off-by: Sam SIU <23556929+ssiuhk@users.noreply.github.com>
Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
@kellyjonbrazil
Copy link
Owner

kellyjonbrazil commented Apr 28, 2024

The fix is now in the dev branch and will be in the next release.

https://github.com/kellyjonbrazil/jc/blob/dev/jc/parsers/pci_ids.py

You can test by copying the parser file above into your parser plugin folder:

  • Linux/unix: $HOME/.local/share/jc/jcparsers
  • macOS: $HOME/Library/Application Support/jc/jcparsers
  • Windows: $LOCALAPPDATA\jc\jc\jcparsers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready-to-ship
Projects
None yet
Development

No branches or pull requests

2 participants