On Tue, Aug 30, 2011 at 10:18 PM, Dan Cornell <d...@denimgroup.com> wrote:
> I was fiddling around with something this weekend and wanted to make sure it
> was valuable before I finished it off.
>
> I've been working to auto-generate Python code to do USB class lookups based
> on the info stored at:
>
> http://www.linux-usb.org/usb.ids
>
> Basically it reads the info in that URL and generates code like:
>
> # USB library
> # Generated on: 2011-08-31 00:16:39.468550
>
> def dev_class_to_string(dev_class_id):
>         if dev_class_id == 0x0:
>                 ret_val = '(Defined at Interface level)'
>         elif dev_class_id == 0x1:
>                 ret_val = 'Audio'
....

I would find this very useful.

I love code generators, however I would suggest a minor change to the
implementation (the api is fine). Shove the data in a dictionary, this
function is basically a dict :-)

E.g.

dev_string = {
    0x0:  '(Defined at Interface level)',
    0x1: 'Audio',
.....
print dev_string[0x1]

There are more appropriate here and more Pythonic. You could even omit
the static dictionary def and include the parsing code to construct
the dict  from a file/url.

> This would need to get cleaned up and better integrated with the overall
> libusb library, but before I went any farther I wanted to check and see if
> this was functionality that was:
>
> -interesting
> -desirable
>
> -etc
>
> There is a bunch of other info at http://www.linux-usb.org/usb.ids with
> vendor and protocol info, etc and the stuff I’ve been putting together to
> include that as well.  Again – just wanted to see if this was
> interesting/useful before I put in the time to make it more complete.
>

+1 from me :-)

Chris

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to