From 5790166c63b1b19f9656bd2345f04ac081026685 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 28 Apr 2009 19:40:57 -0700 Subject: [PATCH] Driver for the Ectaco JetBook by James Ralston --- src/calibre/devices/__init__.py | 3 +- src/calibre/devices/jetbook/__init__.py | 0 src/calibre/devices/jetbook/driver.py | 84 +++++++++++++++++++++++++ src/calibre/devices/usbms/driver.py | 9 ++- src/calibre/gui2/main.py | 4 +- 5 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 src/calibre/devices/jetbook/__init__.py create mode 100644 src/calibre/devices/jetbook/driver.py diff --git a/src/calibre/devices/__init__.py b/src/calibre/devices/__init__.py index 9c515c07fd..cd3cd30734 100644 --- a/src/calibre/devices/__init__.py +++ b/src/calibre/devices/__init__.py @@ -14,8 +14,9 @@ def devices(): from calibre.devices.kindle.driver import KINDLE2 from calibre.devices.blackberry.driver import BLACKBERRY from calibre.devices.eb600.driver import EB600 + from calibre.devices.jetbook.driver import JETBOOK return (PRS500, PRS505, PRS700, CYBOOKG3, KINDLE, KINDLE2, - BLACKBERRY, EB600) + BLACKBERRY, EB600, JETBOOK) import time diff --git a/src/calibre/devices/jetbook/__init__.py b/src/calibre/devices/jetbook/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/calibre/devices/jetbook/driver.py b/src/calibre/devices/jetbook/driver.py new file mode 100644 index 0000000000..fc98773f78 --- /dev/null +++ b/src/calibre/devices/jetbook/driver.py @@ -0,0 +1,84 @@ +__license__ = 'GPL v3' +__copyright__ = '2009, James Ralston ' +''' +Device driver for Ectaco Jetbook firmware >= JL04_v030e +''' + +import os, shutil +from itertools import cycle + +from calibre.devices.errors import FreeSpaceError +from calibre.devices.usbms.driver import USBMS +from calibre.devices.usbms.books import BookList +from calibre import sanitize_file_name as sanitize + +class JETBOOK(USBMS): + # Ordered list of supported formats + # Be sure these have an entry in calibre.devices.mime + FORMATS = [ 'epub', 'mobi', 'prc', 'txt', 'rtf', 'pdf'] + + VENDOR_ID = [0x0525] + PRODUCT_ID = [0xa4a5] + BCD = [0x314] + + VENDOR_NAME = 'NETCHIP' + + WINDOWS_MAIN_MEM = None + WINDOWS_CARD_MEM = None + + OSX_MAIN_MEM = None + OSX_CARD_MEM = None + + MAIN_MEMORY_VOLUME_LABEL = 'Jetbook Main Memory' + STORAGE_CARD_VOLUME_LABEL = 'Jetbook Storage Card' + + EBOOK_DIR_MAIN = "Books" + EBOOK_DIR_CARD = "Books" + SUPPORTS_SUB_DIRS = True + + def upload_books(self, files, names, on_card=False, end_session=True, + metadata=None): + + path = self._sanity_check(on_card, files) + + paths = [] + names = iter(names) + metadata = iter(metadata) + + for infile in files: + newpath = path + + if self.SUPPORTS_SUB_DIRS: + mdata = metadata.next() + + if 'tags' in mdata.keys(): + for tag in mdata['tags']: + if tag.startswith('/'): + newpath += tag + newpath = os.path.normpath(newpath) + break + + if not os.path.exists(newpath): + os.makedirs(newpath) + + author = sanitize(mdata.get('authors','Unknown')) + title = sanitize(mdata.get('title', 'Unknown')) + (basename, fileext) = os.path.splitext(os.path.basename(names.next())) + fname = '%s#%s%s' % (author, title, fileext) + + filepath = os.path.join(newpath, fname) + paths.append(filepath) + + if hasattr(infile, 'read'): + infile.seek(0) + + dest = open(filepath, 'wb') + shutil.copyfileobj(infile, dest, 10*1024*1024) + + dest.flush() + dest.close() + else: + shutil.copy2(infile, filepath) + + return zip(paths, cycle([on_card])) + diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index dfef3b9f38..21a5da77cd 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -71,8 +71,7 @@ def books(self, oncard=False, end_session=True): bl.append(self.__class__.book_from_path(os.path.join(path, filename))) return bl - def upload_books(self, files, names, on_card=False, end_session=True, - metadata=None): + def _sanity_check(self, on_card, files): if on_card and not self._card_prefix: raise ValueError(_('The reader has no storage card connected.')) @@ -96,6 +95,12 @@ def get_size(obj): raise FreeSpaceError(_("There is insufficient free space on the storage card")) if not on_card and size > self.free_space()[0] - 2*1024*1024: raise FreeSpaceError(_("There is insufficient free space in main memory")) + return path + + def upload_books(self, files, names, on_card=False, end_session=True, + metadata=None): + + path = self._sanity_check(on_card, files) paths = [] names = iter(names) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 41077e4e0e..09f95033f1 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -1571,8 +1571,8 @@ def main(args=sys.argv): extra = '' if iswindows else \ ('If you\'re sure it is not running, delete the file ' '%s.'%os.path.expanduser('~/.calibre_calibre GUI.lock')) - QMessageBox.critical(None, 'Cannot Start '+__appname__, - '

%s is already running. %s

'%(__appname__, extra)) + QMessageBox.critical(None, _('Cannot Start ')+__appname__, + _('

%s is already running. %s

')%(__appname__, extra)) return 1 initialize_file_icon_provider() main = Main(single_instance, opts, actions)