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

Fix parsing failed due to assumption of a fixed output format of system_profiler SPUSBDataType #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

phuclv90
Copy link

@phuclv90 phuclv90 commented Jun 10, 2023

This script assumes that all device entries have 6 lines following Product ID which is absolutely not true. Just with a single line change

-devices=`echo "$rawlog" | egrep -B 2 -A 6 "Product ID" | sed 's/^--/#/'`
+devices=`echo "$rawlog" | sed -e '/:$/i\
+#'`

you'll get it mostly work

However it also have many other wrong assumptions like there are 7 lines after the bus name and there are always Location ID or Bus Number. Therefore the tree feature is completely broken. It also prints buses as devices although I don't know why and that makes buses printed twice along with the missing product ID. This can't fix all those issues but will make the tree feature less crippled

This script assumes that all entries have 6 lines following Product ID which is absolutely not true
It also assumes that there are 7 lines after the bus and there are always Location ID or Bus Number
@phuclv90 phuclv90 changed the title Fix parsing failed due to assumption of a fixed format Fix parsing failed due to assumption of a fixed output format of system_profiler SPUSBDataType Jun 10, 2023
@DoctorU
Copy link

DoctorU commented Aug 28, 2023

I have this issue with a device. Would be good to get it merged in. I'm using homebrew to install.
I've run a test on it, and it seems to be good. Let me know if I can provide some sort of test data.

This is the default homebrew install's output:

2023-08-28T10:31:35+00:00 ~/o/lsusb> lsusb -V
lsusb for Mac OS X 007
2023-08-28T10:23:10+00:00 ~/o/lsusb> lsusb
Bus 001 Device 001: ID 05ac:1018 Apple Inc. USB3.1 Hub  Serial: <redacted>
Bus 001 Device 002: ID 05ac:1017 Apple Inc. USB2.0 Hub  Serial: <redacted>
Bus 001 Device 004: ID 16d0:0aec 16d0 EDTracker Pro Wireless
Bus 001 Device 003: ID 05ac:1463 Apple Inc. USB-C Digital AV Multiport Adapter  Serial: <redacted>
/opt/homebrew/bin/lsusb: line 89: 16#: invalid integer constant (error token is "16#")
Bus 000 Device 000: ID 05ac:1018 Apple Inc. USB 3.1 Bus

I cloned @phuclv90's repo and branch, and tested - this is the output:

2023-08-28T10:19:06+00:00 ~> mkdir ./opt; cd ./opt; git clone https://github.com/phuclv90/lsusb.git; cd 
./lsusb
2023-08-28T10:20:01+00:00 ~/o/lsusb> git switch fix_broken_lsusb
Switched to branch 'fix_broken_lsusb'
Your branch is up to date with 'origin/fix_broken_lsusb'.
2023-08-28T10:21:21+00:00 ~/o/lsusb> ./lsusb -V
lsusb for Mac OS X 008
i343999 2023-08-28T10:22:18+00:00 ~/o/lsusb> ./lsusb
Bus 000 Device 001: ID 05ac: Apple Inc. USB
Bus 000 Device 001: ID 05ac:8007 Apple Inc. XHCI Root Hub USB 2.0 Simulation
Bus 000 Device 001: ID 05ac:8007 Apple Inc. XHCI Root Hub USB 2.0 Simulation
Bus 000 Device 001: ID 05ac:8007 Apple Inc. XHCI Root Hub USB 2.0 Simulation
Bus 001 Device 001: ID 05ac:1018 Apple Inc. USB3.1 Hub  Serial: <redacted>
Bus 001 Device 002: ID 05ac:1017 Apple Inc. USB2.0 Hub  Serial: <redacted>
Bus 001 Device 004: ID 16d0:0aec 16d0 EDTracker Pro Wireless
Bus 001 Device 003: ID 05ac:1463 Apple Inc. USB-C Digital AV Multiport Adapter  Serial: <redacted>
Buses:
Bus 000 Device 001: ID 05ac:8007 Apple Inc. XHCI Root Hub USB 2.0 Simulation
Bus 000 Device 001: ID 05ac:8007 Apple Inc. XHCI Root Hub USB 2.0 Simulation
Bus 000 Device 001: ID 05ac:8007 Apple Inc. XHCI Root Hub USB 2.0 Simulation

@phuclv90 phuclv90 mentioned this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants