From cc5be36e5a86cfef6af8990f68b61cca22ee56f1 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Mon, 25 May 2020 15:01:04 +0100 Subject: [PATCH] Add some device free space error handling --- src/calibre/devices/smart_device_app/driver.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 74c2d347ed..ade70a1ef8 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -18,12 +18,12 @@ from threading import Thread from calibre import prints from calibre.constants import numeric_version, DEBUG, cache_dir from calibre.devices.errors import (OpenFailed, OpenFeedback, ControlError, TimeoutError, - InitialConnectionError, PacketError) + InitialConnectionError, PacketError, UserFeedback) from calibre.devices.interface import DevicePlugin, currently_connected_device from calibre.devices.usbms.books import Book, CollectionsBookList from calibre.devices.usbms.deviceconfig import DeviceConfig from calibre.devices.usbms.driver import USBMS -from calibre.devices.utils import build_template_regexp +from calibre.devices.utils import build_template_regexp, sanity_check from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks.metadata import title_sort from calibre.ebooks.metadata.book.base import Metadata @@ -252,6 +252,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): 'SET_LIBRARY_INFO' : 19, 'DELETE_BOOK' : 13, 'DISPLAY_MESSAGE' : 17, + 'ERROR' : 20, 'FREE_SPACE' : 5, 'GET_BOOK_FILE_SEGMENT' : 14, 'GET_BOOK_METADATA' : 15, @@ -702,8 +703,12 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): 'canSupportLpathChanges': True}, print_debug_info=False, wait_for_response=self.can_send_ok_to_sendbook) - if self.can_send_ok_to_sendbook: + if opcode == 'ERROR': + raise UserFeedback(msg='Sending book %s to device failed' % lpath, + details=result.get('message', ''), + level=UserFeedback.ERROR) + return lpath = result.get('lpath', lpath) book_metadata.lpath = lpath self._set_known_metadata(book_metadata) @@ -1464,7 +1469,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): self._debug(names) else: self._debug() - + sanity_check(on_card='', files = files, card_prefixes=[], + free_space=self.free_space()) paths = [] names = iter(names) metadata = iter(metadata)