Android driver: Add an extra customization option to configure the directory to which eboks are sent on the storage cards. Fixes #1045045 (Android save-to directory list honored only for main memory)

This commit is contained in:
Kovid Goyal 2012-09-03 13:04:51 +05:30
parent 0e8b5d6bb4
commit ed05dbaa2d
2 changed files with 48 additions and 26 deletions

View File

@ -186,10 +186,15 @@ class ANDROID(USBMS):
} }
EBOOK_DIR_MAIN = ['eBooks/import', 'wordplayer/calibretransfer', 'Books', EBOOK_DIR_MAIN = ['eBooks/import', 'wordplayer/calibretransfer', 'Books',
'sdcard/ebooks'] 'sdcard/ebooks']
EXTRA_CUSTOMIZATION_MESSAGE = _('Comma separated list of directories to ' EXTRA_CUSTOMIZATION_MESSAGE = [_('Comma separated list of directories to '
'send e-books to on the device. The first one that exists will ' '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') 'be used')
EXTRA_CUSTOMIZATION_DEFAULT = ', '.join(EBOOK_DIR_MAIN) ]
EXTRA_CUSTOMIZATION_DEFAULT = [', '.join(EBOOK_DIR_MAIN), '']
VENDOR_NAME = ['HTC', 'MOTOROLA', 'GOOGLE_', 'ANDROID', 'ACER', VENDOR_NAME = ['HTC', 'MOTOROLA', 'GOOGLE_', 'ANDROID', 'ACER',
'GT-I5700', 'SAMSUNG', 'DELL', 'LINUX', 'GOOGLE', 'ARCHOS', 'GT-I5700', 'SAMSUNG', 'DELL', 'LINUX', 'GOOGLE', 'ARCHOS',
@ -237,23 +242,35 @@ class ANDROID(USBMS):
def post_open_callback(self): def post_open_callback(self):
opts = self.settings() opts = self.settings()
dirs = opts.extra_customization opts = opts.extra_customization
if not dirs: if not opts:
dirs = self.EBOOK_DIR_MAIN opts = [self.EBOOK_DIR_MAIN, '']
else:
dirs = [x.strip() for x in dirs.split(',')] def strtolist(x):
self.EBOOK_DIR_MAIN = dirs 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): def get_main_ebook_dir(self, for_upload=False):
dirs = self.EBOOK_DIR_MAIN dirs = self._android_main_ebook_dir
if not for_upload: if not for_upload:
def aldiko_tweak(x): def aldiko_tweak(x):
return 'eBooks' if x == 'eBooks/import' else x return 'eBooks' if x == 'eBooks/import' else x
if isinstance(dirs, basestring):
dirs = [dirs]
dirs = list(map(aldiko_tweak, dirs)) dirs = list(map(aldiko_tweak, dirs))
return 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): def windows_sort_drives(self, drives):
try: try:
vid, pid, bcd = self.device_being_opened[:3] vid, pid, bcd = self.device_being_opened[:3]
@ -271,7 +288,8 @@ class ANDROID(USBMS):
proxy = cls._configProxy() proxy = cls._configProxy()
proxy['format_map'] = ['mobi', 'azw', 'azw1', 'azw4', 'pdf'] proxy['format_map'] = ['mobi', 'azw', 'azw1', 'azw4', 'pdf']
proxy['use_subdirs'] = False proxy['use_subdirs'] = False
proxy['extra_customization'] = ','.join(['kindle']+cls.EBOOK_DIR_MAIN) proxy['extra_customization'] = [
','.join(['kindle']+cls.EBOOK_DIR_MAIN), '']
@classmethod @classmethod
def configure_for_generic_epub_app(cls): def configure_for_generic_epub_app(cls):

View File

@ -991,24 +991,28 @@ class Device(DeviceConfig, DevicePlugin):
elif on_card and on_card not in ('carda', 'cardb'): elif on_card and on_card not in ('carda', 'cardb'):
raise DeviceError(_('Selected slot: %s is not supported.') % on_card) raise DeviceError(_('Selected slot: %s is not supported.') % on_card)
if on_card == 'carda': def get_dest_dir(prefix, candidates):
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)
if isinstance(candidates, basestring): if isinstance(candidates, basestring):
candidates = [candidates] candidates = [candidates]
if not candidates:
candidates = ['']
candidates = [ candidates = [
((os.path.join(self._main_prefix, *(x.split('/')))) if x else ((os.path.join(prefix, *(x.split('/')))) if x else prefix)
self._main_prefix) for x for x in candidates]
in candidates]
existing = [x for x in candidates if os.path.exists(x)] existing = [x for x in candidates if os.path.exists(x)]
if not existing: if not existing:
existing = candidates[:1] existing = candidates
path = existing[0] 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): def get_size(obj):
path = getattr(obj, 'name', obj) path = getattr(obj, 'name', obj)