mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #4404 (Having trouble connecting HTC Hero - TypeError)
This commit is contained in:
parent
2c5b79f79c
commit
574d5d64bd
@ -455,29 +455,22 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
usb_dir = None
|
usb_dir = None
|
||||||
|
|
||||||
def test(val, attr):
|
def test(val, attr):
|
||||||
q = getattr(self, attr)
|
q = getattr(self.detected_device, attr)
|
||||||
if q is None: return True
|
return q == val
|
||||||
return q == val or val in q
|
|
||||||
|
|
||||||
for x, isfile in walk('/sys/devices'):
|
for x, isfile in walk('/sys/devices'):
|
||||||
if isfile and x.endswith('idVendor'):
|
if isfile and x.endswith('idVendor'):
|
||||||
usb_dir = d(x)
|
usb_dir = d(x)
|
||||||
for y in ('idProduct',):
|
for y in ('idProduct', 'idVendor', 'bcdDevice'):
|
||||||
if not os.access(j(usb_dir, y), os.R_OK):
|
if not os.access(j(usb_dir, y), os.R_OK):
|
||||||
usb_dir = None
|
usb_dir = None
|
||||||
continue
|
continue
|
||||||
e = lambda q : raw2num(open(j(usb_dir, q)).read())
|
e = lambda q : raw2num(open(j(usb_dir, q)).read())
|
||||||
ven, prod = map(e, ('idVendor', 'idProduct'))
|
ven, prod, bcd = map(e, ('idVendor', 'idProduct', 'bcdDevice'))
|
||||||
if not (test(ven, 'VENDOR_ID') and test(prod, 'PRODUCT_ID')):
|
if not (test(ven, 'idVendor') and test(prod, 'idProduct') and
|
||||||
|
test(bcd, 'bcdDevice')):
|
||||||
usb_dir = None
|
usb_dir = None
|
||||||
continue
|
continue
|
||||||
if self.BCD is not None:
|
|
||||||
if not os.access(j(usb_dir, 'bcdDevice'), os.R_OK) or \
|
|
||||||
not test(e('bcdDevice'), 'BCD'):
|
|
||||||
usb_dir = None
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user