Fix #6956 (ALEX features)

This commit is contained in:
Kovid Goyal 2010-10-01 12:10:53 -06:00
parent d8f4936bfb
commit 44339bd67a

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
''' '''
Device driver for Hanvon devices Device driver for Hanvon devices
''' '''
import re import re, os
from calibre.devices.usbms.driver import USBMS from calibre.devices.usbms.driver import USBMS
@ -67,10 +67,50 @@ class ALEX(N516):
EBOOK_DIR_MAIN = 'eBooks' EBOOK_DIR_MAIN = 'eBooks'
SUPPORTS_SUB_DIRS = False SUPPORTS_SUB_DIRS = False
THUMBNAIL_HEIGHT = 120
def can_handle(self, device_info, debug=False): def can_handle(self, device_info, debug=False):
return is_alex(device_info) return is_alex(device_info)
def alex_cpath(self, file_abspath):
base = os.path.dirname(file_abspath)
name = os.path.splitext(os.path.basename(file_abspath))[0] + '.png'
return os.path.join(base, 'covers', name)
def upload_cover(self, path, filename, metadata):
from calibre.ebooks import calibre_cover
from calibre.utils.magick.draw import thumbnail
coverdata = getattr(metadata, 'thumbnail', None)
if coverdata and coverdata[2]:
cover = coverdata[2]
else:
cover = calibre_cover(metadata.get('title', _('Unknown')),
metadata.get('authors', _('Unknown')))
cover = thumbnail(cover, width=self.THUMBNAIL_HEIGHT,
height=self.THUMBNAIL_HEIGHT, fmt='png')[-1]
cpath = self.alex_cpath(os.path.join(path, filename))
cdir = os.path.dirname(cpath)
if not os.path.exists(cdir):
os.makedirs(cdir)
with open(cpath, 'wb') as coverfile:
coverfile.write(cover)
def delete_books(self, paths, end_session=True):
for i, path in enumerate(paths):
self.report_progress((i+1) / float(len(paths)), _('Removing books from device...'))
path = self.normalize_path(path)
if os.path.exists(path):
# Delete the ebook
os.unlink(path)
try:
cpath = self.alex_cpath(path)
if os.path.exists(cpath):
os.remove(cpath)
except:
pass
class AZBOOKA(ALEX): class AZBOOKA(ALEX):
name = 'Azbooka driver' name = 'Azbooka driver'
@ -83,10 +123,13 @@ class AZBOOKA(ALEX):
MAIN_MEMORY_VOLUME_LABEL = 'Azbooka Internal Memory' MAIN_MEMORY_VOLUME_LABEL = 'Azbooka Internal Memory'
EBOOK_DIR_MAIN = '' EBOOK_DIR_MAIN = ''
SUPPORTS_SUB_DIRS = True
def can_handle(self, device_info, debug=False): def can_handle(self, device_info, debug=False):
return not is_alex(device_info) return not is_alex(device_info)
def upload_cover(self, path, filename, metadata):
pass
class EB511(USBMS): class EB511(USBMS):
name = 'Elonex EB 511 driver' name = 'Elonex EB 511 driver'