diff --git a/src/calibre/devices/android/driver.py b/src/calibre/devices/android/driver.py index 9e8aa5fe17..efe979158d 100644 --- a/src/calibre/devices/android/driver.py +++ b/src/calibre/devices/android/driver.py @@ -186,10 +186,15 @@ class ANDROID(USBMS): } EBOOK_DIR_MAIN = ['eBooks/import', 'wordplayer/calibretransfer', 'Books', 'sdcard/ebooks'] - EXTRA_CUSTOMIZATION_MESSAGE = _('Comma separated list of directories to ' - 'send e-books to on the device. The first one that exists will ' + EXTRA_CUSTOMIZATION_MESSAGE = [_('Comma separated list of directories to ' + 'send e-books to on the device\'s main memory. The first one that exists will ' + 'be used'), + _('Comma separated list of directories to ' + 'send e-books to on the device\'s storage cards. The first one that exists will ' 'be used') - EXTRA_CUSTOMIZATION_DEFAULT = ', '.join(EBOOK_DIR_MAIN) + ] + + EXTRA_CUSTOMIZATION_DEFAULT = [', '.join(EBOOK_DIR_MAIN), ''] VENDOR_NAME = ['HTC', 'MOTOROLA', 'GOOGLE_', 'ANDROID', 'ACER', 'GT-I5700', 'SAMSUNG', 'DELL', 'LINUX', 'GOOGLE', 'ARCHOS', @@ -237,23 +242,35 @@ class ANDROID(USBMS): def post_open_callback(self): opts = self.settings() - dirs = opts.extra_customization - if not dirs: - dirs = self.EBOOK_DIR_MAIN - else: - dirs = [x.strip() for x in dirs.split(',')] - self.EBOOK_DIR_MAIN = dirs + opts = opts.extra_customization + if not opts: + opts = [self.EBOOK_DIR_MAIN, ''] + + def strtolist(x): + if isinstance(x, basestring): + x = [y.strip() for y in x.split(',')] + return x or [] + + opts = [strtolist(x) for x in opts] + self._android_main_ebook_dir = opts[0] + self._android_card_ebook_dir = opts[1] def get_main_ebook_dir(self, for_upload=False): - dirs = self.EBOOK_DIR_MAIN + dirs = self._android_main_ebook_dir if not for_upload: def aldiko_tweak(x): return 'eBooks' if x == 'eBooks/import' else x - if isinstance(dirs, basestring): - dirs = [dirs] dirs = list(map(aldiko_tweak, dirs)) return dirs + def get_carda_ebook_dir(self, for_upload=False): + if not for_upload: + return '' + return self._android_card_ebook_dir + + def get_cardb_ebook_dir(self, for_upload=False): + return self.get_carda_ebook_dir() + def windows_sort_drives(self, drives): try: vid, pid, bcd = self.device_being_opened[:3] @@ -271,7 +288,8 @@ class ANDROID(USBMS): proxy = cls._configProxy() proxy['format_map'] = ['mobi', 'azw', 'azw1', 'azw4', 'pdf'] proxy['use_subdirs'] = False - proxy['extra_customization'] = ','.join(['kindle']+cls.EBOOK_DIR_MAIN) + proxy['extra_customization'] = [ + ','.join(['kindle']+cls.EBOOK_DIR_MAIN), ''] @classmethod def configure_for_generic_epub_app(cls): diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 4d4b198de0..025a7e2d95 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -991,24 +991,28 @@ class Device(DeviceConfig, DevicePlugin): elif on_card and on_card not in ('carda', 'cardb'): raise DeviceError(_('Selected slot: %s is not supported.') % on_card) - if on_card == 'carda': - path = os.path.join(self._card_a_prefix, - *(self.get_carda_ebook_dir(for_upload=True).split('/'))) - elif on_card == 'cardb': - path = os.path.join(self._card_b_prefix, - *(self.EBOOK_DIR_CARD_B.split('/'))) - else: - candidates = self.get_main_ebook_dir(for_upload=True) + def get_dest_dir(prefix, candidates): if isinstance(candidates, basestring): candidates = [candidates] + if not candidates: + candidates = [''] candidates = [ - ((os.path.join(self._main_prefix, *(x.split('/')))) if x else - self._main_prefix) for x - in candidates] + ((os.path.join(prefix, *(x.split('/')))) if x else prefix) + for x in candidates] existing = [x for x in candidates if os.path.exists(x)] if not existing: - existing = candidates[:1] - path = existing[0] + existing = candidates + return existing[0] + + if on_card == 'carda': + candidates = self.get_carda_ebook_dir(for_upload=True) + path = get_dest_dir(self._carda_prefix, candidates) + elif on_card == 'cardb': + candidates = self.get_cardb_ebook_dir(for_upload=True) + path = get_dest_dir(self._cardb_prefix, candidates) + else: + candidates = self.get_main_ebook_dir(for_upload=True) + path = get_dest_dir(self._main_prefix, candidates) def get_size(obj): path = getattr(obj, 'name', obj)