mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Device subsystem: Make the USB ids of the device being opened available to the driver while open() is being called.
This commit is contained in:
parent
23caca5f47
commit
e082bf17f2
@ -39,15 +39,15 @@ def get_connected_device():
|
|||||||
if ok:
|
if ok:
|
||||||
dev = d
|
dev = d
|
||||||
dev.reset(log_packets=False, detected_device=det)
|
dev.reset(log_packets=False, detected_device=det)
|
||||||
connected_devices.append(dev)
|
connected_devices.append((det, dev))
|
||||||
|
|
||||||
if dev is None:
|
if dev is None:
|
||||||
print >>sys.stderr, 'Unable to find a connected ebook reader.'
|
print >>sys.stderr, 'Unable to find a connected ebook reader.'
|
||||||
return
|
return
|
||||||
|
|
||||||
for d in connected_devices:
|
for det, d in connected_devices:
|
||||||
try:
|
try:
|
||||||
d.open(None)
|
d.open(det, None)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -121,7 +121,7 @@ def debug(ioreg_to_tmp=False, buf=None):
|
|||||||
out('Trying to open', dev.name, '...', end=' ')
|
out('Trying to open', dev.name, '...', end=' ')
|
||||||
try:
|
try:
|
||||||
dev.reset(detected_device=det)
|
dev.reset(detected_device=det)
|
||||||
dev.open(None)
|
dev.open(det, None)
|
||||||
out('OK')
|
out('OK')
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -808,7 +808,7 @@ class ITUNES(DriverBase):
|
|||||||
self.log.info("ITUNES.get_file(): exporting '%s'" % path)
|
self.log.info("ITUNES.get_file(): exporting '%s'" % path)
|
||||||
outfile.write(open(self.cached_books[path]['lib_book'].location().path).read())
|
outfile.write(open(self.cached_books[path]['lib_book'].location().path).read())
|
||||||
|
|
||||||
def open(self, library_uuid):
|
def open(self, connected_device, library_uuid):
|
||||||
'''
|
'''
|
||||||
Perform any device specific initialization. Called after the device is
|
Perform any device specific initialization. Called after the device is
|
||||||
detected but before any other functions that communicate with the device.
|
detected but before any other functions that communicate with the device.
|
||||||
@ -3224,7 +3224,7 @@ class ITUNES_ASYNC(ITUNES):
|
|||||||
only_presence=False):
|
only_presence=False):
|
||||||
return self.connected, self
|
return self.connected, self
|
||||||
|
|
||||||
def open(self, library_uuid):
|
def open(self, connected_device, library_uuid):
|
||||||
'''
|
'''
|
||||||
Perform any device specific initialization. Called after the device is
|
Perform any device specific initialization. Called after the device is
|
||||||
detected but before any other functions that communicate with the device.
|
detected but before any other functions that communicate with the device.
|
||||||
|
@ -59,9 +59,9 @@ class BAMBOOK(DeviceConfig, DevicePlugin):
|
|||||||
|
|
||||||
def reset(self, key='-1', log_packets=False, report_progress=None,
|
def reset(self, key='-1', log_packets=False, report_progress=None,
|
||||||
detected_device=None) :
|
detected_device=None) :
|
||||||
self.open(None)
|
self.open(None, None)
|
||||||
|
|
||||||
def open(self, library_uuid):
|
def open(self, connected_device, library_uuid):
|
||||||
# Make sure the Bambook library is ready
|
# Make sure the Bambook library is ready
|
||||||
if not is_bambook_lib_ready():
|
if not is_bambook_lib_ready():
|
||||||
raise OpenFeedback(_("Unable to connect to Bambook, you need to install Bambook library first."))
|
raise OpenFeedback(_("Unable to connect to Bambook, you need to install Bambook library first."))
|
||||||
@ -309,8 +309,8 @@ class BAMBOOK(DeviceConfig, DevicePlugin):
|
|||||||
with TemporaryFile('.snb') as snbfile:
|
with TemporaryFile('.snb') as snbfile:
|
||||||
if self.bambook.PackageSNB(snbfile, tdir) and self.bambook.VerifySNB(snbfile):
|
if self.bambook.PackageSNB(snbfile, tdir) and self.bambook.VerifySNB(snbfile):
|
||||||
guid = self.bambook.SendFile(snbfile, self.get_guid(metadata[i].uuid))
|
guid = self.bambook.SendFile(snbfile, self.get_guid(metadata[i].uuid))
|
||||||
|
|
||||||
elif f[-3:].upper() == 'SNB':
|
elif f[-3:].upper() == 'SNB':
|
||||||
if self.bambook.VerifySNB(f):
|
if self.bambook.VerifySNB(f):
|
||||||
guid = self.bambook.SendFile(f, self.get_guid(metadata[i].uuid))
|
guid = self.bambook.SendFile(f, self.get_guid(metadata[i].uuid))
|
||||||
else:
|
else:
|
||||||
|
@ -79,7 +79,7 @@ class FOLDER_DEVICE(USBMS):
|
|||||||
only_presence=False):
|
only_presence=False):
|
||||||
return self.is_connected, self
|
return self.is_connected, self
|
||||||
|
|
||||||
def open(self, library_uuid):
|
def open(self, connected_device, library_uuid):
|
||||||
self.current_library_uuid = library_uuid
|
self.current_library_uuid = library_uuid
|
||||||
if not self._main_prefix:
|
if not self._main_prefix:
|
||||||
return False
|
return False
|
||||||
|
@ -133,8 +133,14 @@ class DevicePlugin(Plugin):
|
|||||||
if debug:
|
if debug:
|
||||||
self.print_usb_device_info(device_id)
|
self.print_usb_device_info(device_id)
|
||||||
if only_presence or self.can_handle_windows(device_id, debug=debug):
|
if only_presence or self.can_handle_windows(device_id, debug=debug):
|
||||||
return True
|
try:
|
||||||
return False
|
bcd = int(device_id.rpartition(
|
||||||
|
'rev_')[-1].replace(':', 'a'), 16)
|
||||||
|
except:
|
||||||
|
bcd = None
|
||||||
|
return True, (vendor_id, product_id, bcd, None,
|
||||||
|
None, None)
|
||||||
|
return False, None
|
||||||
|
|
||||||
def test_bcd(self, bcdDevice, bcd):
|
def test_bcd(self, bcdDevice, bcd):
|
||||||
if bcd is None or len(bcd) == 0:
|
if bcd is None or len(bcd) == 0:
|
||||||
@ -154,7 +160,7 @@ class DevicePlugin(Plugin):
|
|||||||
'''
|
'''
|
||||||
if iswindows:
|
if iswindows:
|
||||||
return self.is_usb_connected_windows(devices_on_system,
|
return self.is_usb_connected_windows(devices_on_system,
|
||||||
debug=debug, only_presence=only_presence), None
|
debug=debug, only_presence=only_presence)
|
||||||
|
|
||||||
vendors_on_system = set([x[0] for x in devices_on_system])
|
vendors_on_system = set([x[0] for x in devices_on_system])
|
||||||
vendors = self.VENDOR_ID if hasattr(self.VENDOR_ID, '__len__') else [self.VENDOR_ID]
|
vendors = self.VENDOR_ID if hasattr(self.VENDOR_ID, '__len__') else [self.VENDOR_ID]
|
||||||
@ -224,7 +230,7 @@ class DevicePlugin(Plugin):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def open(self, library_uuid):
|
def open(self, connected_device, library_uuid):
|
||||||
'''
|
'''
|
||||||
Perform any device specific initialization. Called after the device is
|
Perform any device specific initialization. Called after the device is
|
||||||
detected but before any other functions that communicate with the device.
|
detected but before any other functions that communicate with the device.
|
||||||
@ -238,6 +244,16 @@ class DevicePlugin(Plugin):
|
|||||||
|
|
||||||
This method can raise an OpenFeedback exception to display a message to
|
This method can raise an OpenFeedback exception to display a message to
|
||||||
the user.
|
the user.
|
||||||
|
|
||||||
|
:param connected_device: The device that we are trying to open. It is
|
||||||
|
a tuple of (vendor id, product id, bcd, manufacturer name, product
|
||||||
|
name, device serial number). However, some device have no serial number
|
||||||
|
and on windows only the first three fields are present, the rest are
|
||||||
|
None.
|
||||||
|
|
||||||
|
:param library_uuid: The UUID of the current calibre library. Can be
|
||||||
|
None if there is no library (for example when used from the command
|
||||||
|
line.
|
||||||
'''
|
'''
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -205,15 +205,15 @@ def main():
|
|||||||
if ok:
|
if ok:
|
||||||
dev = d
|
dev = d
|
||||||
dev.reset(log_packets=options.log_packets, detected_device=det)
|
dev.reset(log_packets=options.log_packets, detected_device=det)
|
||||||
connected_devices.append(dev)
|
connected_devices.append((det, dev))
|
||||||
|
|
||||||
if dev is None:
|
if dev is None:
|
||||||
print >>sys.stderr, 'Unable to find a connected ebook reader.'
|
print >>sys.stderr, 'Unable to find a connected ebook reader.'
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
for d in connected_devices:
|
for det, d in connected_devices:
|
||||||
try:
|
try:
|
||||||
d.open(None)
|
d.open(det, None)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -240,7 +240,7 @@ class PRS500(DeviceConfig, DevicePlugin):
|
|||||||
def set_progress_reporter(self, report_progress):
|
def set_progress_reporter(self, report_progress):
|
||||||
self.report_progress = report_progress
|
self.report_progress = report_progress
|
||||||
|
|
||||||
def open(self, library_uuid) :
|
def open(self, connected_device, library_uuid) :
|
||||||
"""
|
"""
|
||||||
Claim an interface on the device for communication.
|
Claim an interface on the device for communication.
|
||||||
Requires write privileges to the device file.
|
Requires write privileges to the device file.
|
||||||
|
@ -847,38 +847,42 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
self._card_b_prefix = None
|
self._card_b_prefix = None
|
||||||
# ------------------------------------------------------
|
# ------------------------------------------------------
|
||||||
|
|
||||||
def open(self, library_uuid):
|
def open(self, connected_device, library_uuid):
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
self._main_prefix = self._card_a_prefix = self._card_b_prefix = None
|
self._main_prefix = self._card_a_prefix = self._card_b_prefix = None
|
||||||
if islinux:
|
self.device_being_opened = connected_device
|
||||||
try:
|
try:
|
||||||
self.open_linux()
|
if islinux:
|
||||||
except DeviceError:
|
try:
|
||||||
time.sleep(7)
|
self.open_linux()
|
||||||
self.open_linux()
|
except DeviceError:
|
||||||
if isfreebsd:
|
time.sleep(7)
|
||||||
self._main_dev = self._card_a_dev = self._card_b_dev = None
|
self.open_linux()
|
||||||
try:
|
if isfreebsd:
|
||||||
self.open_freebsd()
|
self._main_dev = self._card_a_dev = self._card_b_dev = None
|
||||||
except DeviceError:
|
try:
|
||||||
subprocess.Popen(["camcontrol", "rescan", "all"])
|
self.open_freebsd()
|
||||||
time.sleep(2)
|
except DeviceError:
|
||||||
self.open_freebsd()
|
subprocess.Popen(["camcontrol", "rescan", "all"])
|
||||||
if iswindows:
|
time.sleep(2)
|
||||||
try:
|
self.open_freebsd()
|
||||||
self.open_windows()
|
if iswindows:
|
||||||
except DeviceError:
|
try:
|
||||||
time.sleep(7)
|
self.open_windows()
|
||||||
self.open_windows()
|
except DeviceError:
|
||||||
if isosx:
|
time.sleep(7)
|
||||||
try:
|
self.open_windows()
|
||||||
self.open_osx()
|
if isosx:
|
||||||
except DeviceError:
|
try:
|
||||||
time.sleep(7)
|
self.open_osx()
|
||||||
self.open_osx()
|
except DeviceError:
|
||||||
|
time.sleep(7)
|
||||||
|
self.open_osx()
|
||||||
|
|
||||||
self.current_library_uuid = library_uuid
|
self.current_library_uuid = library_uuid
|
||||||
self.post_open_callback()
|
self.post_open_callback()
|
||||||
|
finally:
|
||||||
|
self.device_being_opened = None
|
||||||
|
|
||||||
def post_open_callback(self):
|
def post_open_callback(self):
|
||||||
pass
|
pass
|
||||||
|
@ -162,7 +162,7 @@ class DeviceManager(Thread): # {{{
|
|||||||
try:
|
try:
|
||||||
dev.reset(detected_device=detected_device,
|
dev.reset(detected_device=detected_device,
|
||||||
report_progress=self.report_progress)
|
report_progress=self.report_progress)
|
||||||
dev.open(self.current_library_uuid)
|
dev.open(detected_device, self.current_library_uuid)
|
||||||
except OpenFeedback as e:
|
except OpenFeedback as e:
|
||||||
if dev not in self.ejected_devices:
|
if dev not in self.ejected_devices:
|
||||||
self.open_feedback_msg(dev.get_gui_name(), e)
|
self.open_feedback_msg(dev.get_gui_name(), e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user