From: chris c. <cl...@gm...> - 2011-08-28 00:32:39
|
I know pyusb (in svn) is currently not really supported/ready but I have a usability question/observation. If I have a (dumb) example script that uses the "basic" logging settings and pyusb fails to load a backend the OpenUSB load attempt ends up being logged when it too fails, a traceback is also dumped (the script keeps on going). Example script and output ## -------------------- cut here -- """List usb devices using basic logging. This shows conflicts with pyusb logging implementation. """ import logging do_logging = True # And demo problem #do_logging = False # Pick one :) log = logging if do_logging: log.info('hello from test app, no more logging wil be issued form this script') import usb.core import usb.util import usb.backend.libusb10 # Monkey patch libusb10 away, or simply run on a machine without libusb10 def fake_get(): return None usb.backend.libusb10.get_backend = fake_get for dev in usb.core.find(find_all=True): print dev ## -------------------- cut here -- ## -------------------- cut here -- ERROR:usb.backend.openusb:Error loading OpenUSB backend Traceback (most recent call last): File "/home/clach04/dev/python/usb/pyusb/trunk/usb/backend/openusb.py", line 598, in get_backend _lib = _load_library() File "/home/clach04/dev/python/usb/pyusb/trunk/usb/backend/openusb.py", line 148, in _load_library raise OSError('USB library could not be found') OSError: USB library could not be found <usb.core.Device object at 0x9d4f84c> <usb.core.Device object at 0x9d4f8cc> <usb.core.Device object at 0x9d4f92c> <usb.core.Device object at 0x9d4f96c> <usb.core.Device object at 0x9d4f9ac> <usb.core.Device object at 0x9d4f9ec> <usb.core.Device object at 0x9d4fa2c> <usb.core.Device object at 0x9d4fa6c> ## -------------------- cut here -- is there a way to disable this behavior? I'm guessing this is some debug code that is causing this. There are 2 issues: 1) the back trace that gets dumped out 2) the error gets logged (without logging for the usb.backend.openusb logger being (explictly) turned on by the caller. #2 is probably fixable by explicitly setting a log level (of off) in the pyusb code. I could look into doing that if it would be helpful. The workarounds are: 1) Don't use the basic logger in a user script, e.g. add something like; log = logging.getLogger('mylogger') to the user script 2) use libusb10 It isn't a huge issue but a little odd. Thanks! Chris |