mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
5b89f3fe4e
@ -525,10 +525,15 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
# Network functions
|
# Network functions
|
||||||
|
|
||||||
def _read_binary_from_net(self, length):
|
def _read_binary_from_net(self, length):
|
||||||
|
try:
|
||||||
self.device_socket.settimeout(self.MAX_CLIENT_COMM_TIMEOUT)
|
self.device_socket.settimeout(self.MAX_CLIENT_COMM_TIMEOUT)
|
||||||
v = self.device_socket.recv(length)
|
v = self.device_socket.recv(length)
|
||||||
self.device_socket.settimeout(None)
|
self.device_socket.settimeout(None)
|
||||||
return v
|
return v
|
||||||
|
except:
|
||||||
|
self._close_device_socket()
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def _read_string_from_net(self):
|
def _read_string_from_net(self):
|
||||||
data = bytes(0)
|
data = bytes(0)
|
||||||
@ -556,23 +561,30 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
def _send_byte_string(self, sock, s):
|
def _send_byte_string(self, sock, s):
|
||||||
if not isinstance(s, bytes):
|
if not isinstance(s, bytes):
|
||||||
self._debug('given a non-byte string!')
|
self._debug('given a non-byte string!')
|
||||||
|
self._close_device_socket()
|
||||||
raise PacketError("Internal error: found a string that isn't bytes")
|
raise PacketError("Internal error: found a string that isn't bytes")
|
||||||
sent_len = 0
|
sent_len = 0
|
||||||
total_len = len(s)
|
total_len = len(s)
|
||||||
while sent_len < total_len:
|
while sent_len < total_len:
|
||||||
try:
|
try:
|
||||||
|
sock.settimeout(self.MAX_CLIENT_COMM_TIMEOUT)
|
||||||
if sent_len == 0:
|
if sent_len == 0:
|
||||||
amt_sent = sock.send(s)
|
amt_sent = sock.send(s)
|
||||||
else:
|
else:
|
||||||
amt_sent = sock.send(s[sent_len:])
|
amt_sent = sock.send(s[sent_len:])
|
||||||
|
sock.settimeout(None)
|
||||||
if amt_sent <= 0:
|
if amt_sent <= 0:
|
||||||
raise IOError('Bad write on socket')
|
raise IOError('Bad write on socket')
|
||||||
sent_len += amt_sent
|
sent_len += amt_sent
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
self._debug('socket error', e, e.errno)
|
self._debug('socket error', e, e.errno)
|
||||||
if e.args[0] != EAGAIN and e.args[0] != EINTR:
|
if e.args[0] != EAGAIN and e.args[0] != EINTR:
|
||||||
|
self._close_device_socket()
|
||||||
raise
|
raise
|
||||||
time.sleep(0.1) # lets not hammer the OS too hard
|
time.sleep(0.1) # lets not hammer the OS too hard
|
||||||
|
except:
|
||||||
|
self._close_device_socket()
|
||||||
|
raise
|
||||||
|
|
||||||
# This must be protected by a lock because it is called from the GUI thread
|
# This must be protected by a lock because it is called from the GUI thread
|
||||||
# (the sync stuff) and the device manager thread
|
# (the sync stuff) and the device manager thread
|
||||||
@ -592,7 +604,6 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
s = self._json_encode(self.opcodes[op], arg)
|
s = self._json_encode(self.opcodes[op], arg)
|
||||||
if print_debug_info and extra_debug:
|
if print_debug_info and extra_debug:
|
||||||
self._debug('send string', s)
|
self._debug('send string', s)
|
||||||
self.device_socket.settimeout(self.MAX_CLIENT_COMM_TIMEOUT)
|
|
||||||
self._send_byte_string(self.device_socket, (b'%d' % len(s)) + s)
|
self._send_byte_string(self.device_socket, (b'%d' % len(s)) + s)
|
||||||
if not wait_for_response:
|
if not wait_for_response:
|
||||||
return None, None
|
return None, None
|
||||||
@ -617,7 +628,6 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
extra_debug = self.settings().extra_customization[self.OPT_EXTRA_DEBUG]
|
extra_debug = self.settings().extra_customization[self.OPT_EXTRA_DEBUG]
|
||||||
try:
|
try:
|
||||||
v = self._read_string_from_net()
|
v = self._read_string_from_net()
|
||||||
self.device_socket.settimeout(None)
|
|
||||||
if print_debug_info and extra_debug:
|
if print_debug_info and extra_debug:
|
||||||
self._debug('received string', v)
|
self._debug('received string', v)
|
||||||
if v:
|
if v:
|
||||||
@ -655,10 +665,10 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
'metadata': book_metadata, 'thisBook': this_book,
|
'metadata': book_metadata, 'thisBook': this_book,
|
||||||
'totalBooks': total_books,
|
'totalBooks': total_books,
|
||||||
'willStreamBooks': True,
|
'willStreamBooks': True,
|
||||||
'willStreamBinary' : True},
|
'willStreamBinary' : True,
|
||||||
|
'wantsSendOkToSendbook' : self.can_send_ok_to_sendbook},
|
||||||
print_debug_info=False,
|
print_debug_info=False,
|
||||||
wait_for_response=False)
|
wait_for_response=self.can_send_ok_to_sendbook)
|
||||||
|
|
||||||
self._set_known_metadata(book_metadata)
|
self._set_known_metadata(book_metadata)
|
||||||
pos = 0
|
pos = 0
|
||||||
failed = False
|
failed = False
|
||||||
@ -1029,6 +1039,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
|
|||||||
self._debug('Device can use cached metadata', self.client_can_use_metadata_cache)
|
self._debug('Device can use cached metadata', self.client_can_use_metadata_cache)
|
||||||
self.client_cache_uses_lpaths = result.get('cacheUsesLpaths', False)
|
self.client_cache_uses_lpaths = result.get('cacheUsesLpaths', False)
|
||||||
self._debug('Cache uses lpaths', self.client_cache_uses_lpaths)
|
self._debug('Cache uses lpaths', self.client_cache_uses_lpaths)
|
||||||
|
self.can_send_ok_to_sendbook = result.get('canSendOkToSendbook', False)
|
||||||
|
self._debug('Can send OK to sendbook', self.can_send_ok_to_sendbook)
|
||||||
|
|
||||||
if not self.settings().extra_customization[self.OPT_USE_METADATA_CACHE]:
|
if not self.settings().extra_customization[self.OPT_USE_METADATA_CACHE]:
|
||||||
self.client_can_use_metadata_cache = False
|
self.client_can_use_metadata_cache = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user