mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More debug prints
This commit is contained in:
parent
2eed1cf179
commit
d1d0c606fa
@ -813,11 +813,15 @@ def get_usb_info(usbdev, debug=False): # {{{
|
|||||||
try:
|
try:
|
||||||
parent = next(iterancestors(usbdev.devinst))
|
parent = next(iterancestors(usbdev.devinst))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
|
if debug:
|
||||||
|
prints('Cannot get USB info as device has no parent (was probably disconnected)')
|
||||||
return ans
|
return ans
|
||||||
for devinfo, parent_path in DeviceSet(guid=GUID_DEVINTERFACE_USB_HUB).interfaces():
|
for devinfo, parent_path in DeviceSet(guid=GUID_DEVINTERFACE_USB_HUB).interfaces():
|
||||||
if devinfo.DevInst == parent:
|
if devinfo.DevInst == parent:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
if debug:
|
||||||
|
prints('Cannot get USB info as parent of device is not a HUB')
|
||||||
return ans
|
return ans
|
||||||
for devlist, devinfo in DeviceSet(guid=GUID_DEVINTERFACE_USB_DEVICE).devices():
|
for devlist, devinfo in DeviceSet(guid=GUID_DEVINTERFACE_USB_DEVICE).devices():
|
||||||
if devinfo.DevInst == usbdev.devinst:
|
if devinfo.DevInst == usbdev.devinst:
|
||||||
@ -825,6 +829,10 @@ def get_usb_info(usbdev, debug=False): # {{{
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return ans
|
return ans
|
||||||
|
if not device_port:
|
||||||
|
if debug:
|
||||||
|
prints('Cannot get usb info as the SPDRP_ADDRESS property is not present int he registry (can happen with broken USB hub drivers)')
|
||||||
|
return ans
|
||||||
handle = CreateFile(parent_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING, 0, None)
|
handle = CreateFile(parent_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING, 0, None)
|
||||||
try:
|
try:
|
||||||
buf, dd = get_device_descriptor(handle, device_port)
|
buf, dd = get_device_descriptor(handle, device_port)
|
||||||
@ -838,10 +846,11 @@ def get_usb_info(usbdev, debug=False): # {{{
|
|||||||
buf, ans[name] = get_device_string(handle, device_port, index, buf=buf)
|
buf, ans[name] = get_device_string(handle, device_port, index, buf=buf)
|
||||||
except WindowsError as err:
|
except WindowsError as err:
|
||||||
if debug:
|
if debug:
|
||||||
if err.winerror == ERROR_GEN_FAILURE:
|
# Note that I have observed that this fails
|
||||||
prints('Failed to read %s from device, try rebooting the device' % name)
|
# randomly after some time of my Kindle being
|
||||||
else:
|
# connected. Disconnecting and reconnecting causes
|
||||||
prints('Failed to read %s from device, with error: %s' % (name, as_unicode(err)))
|
# it to start working again.
|
||||||
|
prints('Failed to read %s from device, with error: [%d] %s' % (name, err.winerror, as_unicode(err)))
|
||||||
finally:
|
finally:
|
||||||
CloseHandle(handle)
|
CloseHandle(handle)
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user