Kindle driver for OSX and Windows. Better Cybook detection in windows. The prs500 command now supports the Cybook and Kindle drivers.

This commit is contained in:
Kovid Goyal 2009-01-17 12:42:47 -08:00
commit 7057fb8662
4 changed files with 57 additions and 16 deletions

View File

@ -10,7 +10,7 @@ def devices():
from calibre.devices.prs505.driver import PRS505 from calibre.devices.prs505.driver import PRS505
from calibre.devices.prs700.driver import PRS700 from calibre.devices.prs700.driver import PRS700
from calibre.devices.cybookg3.driver import CYBOOKG3 from calibre.devices.cybookg3.driver import CYBOOKG3
#from calibre.devices.kindle.driver import KINDLE from calibre.devices.kindle.driver import KINDLE
return (PRS500, PRS505, PRS700, CYBOOKG3) return (PRS500, PRS505, PRS700, CYBOOKG3)
import time import time
@ -31,4 +31,4 @@ def strftime(epoch, zone=time.gmtime):
src = time.strftime("%w, %d %m %Y %H:%M:%S GMT", zone(epoch)).split() src = time.strftime("%w, %d %m %Y %H:%M:%S GMT", zone(epoch)).split()
src[0] = INVERSE_DAY_MAP[int(src[0][:-1])]+',' src[0] = INVERSE_DAY_MAP[int(src[0][:-1])]+','
src[2] = INVERSE_MONTH_MAP[int(src[2])] src[2] = INVERSE_MONTH_MAP[int(src[2])]
return ' '.join(src) return ' '.join(src)

View File

@ -36,17 +36,15 @@ class CYBOOKG3(USBMS):
os.unlink(path) os.unlink(path)
filepath, ext = os.path.splitext(path) filepath, ext = os.path.splitext(path)
basepath, filename = os.path.split(filepath)
# Delete the ebook auxiliary file # Delete the ebook auxiliary file
if os.path.exists(filepath + '.mbp'): if os.path.exists(filepath + '.mbp'):
os.unlink(filepath + '.mbp') os.unlink(filepath + '.mbp')
# Delete the thumbnails file auto generated for the ebook # Delete the thumbnails file auto generated for the ebook
for p, d, files in os.walk(basepath): if os.path.exists(filepath + '_6090.t2b'):
for filen in fnmatch.filter(files, filename + "*.t2b"): os.unlink(filepath + '_6090.t2b')
os.unlink(os.path.join(p, filen))
try: try:
os.removedirs(os.path.dirname(path)) os.removedirs(os.path.dirname(path))
except: except:

View File

@ -16,13 +16,18 @@ class KINDLE(USBMS):
PRODUCT_ID = 0x0001 PRODUCT_ID = 0x0001
BCD = [0x399] BCD = [0x399]
VENDOR_NAME = 'AMAZON' VENDOR_NAME = 'KINDLE'
WINDOWS_MAIN_MEM = 'KINDLE' WINDOWS_MAIN_MEM = 'INTERNAL_STORAGE'
WINDOWS_CARD_MEM = 'CARD_STORAGE'
OSX_MAIN_MEM = 'Kindle Internal Storage Media'
OSX_CARD_MEM = 'Kindle Card Storage Media'
MAIN_MEMORY_VOLUME_LABEL = 'Kindle Main Memory' MAIN_MEMORY_VOLUME_LABEL = 'Kindle Main Memory'
STORAGE_CARD_VOLUME_LABEL = 'Kindle Storage Card' STORAGE_CARD_VOLUME_LABEL = 'Kindle Storage Card'
EBOOK_DIR_MAIN = "documents" EBOOK_DIR_MAIN = "documents"
SUPPORTS_SUB_DIRS = True
def delete_books(self, paths, end_session=True): def delete_books(self, paths, end_session=True):
for path in paths: for path in paths:

View File

@ -125,10 +125,11 @@ class USBMS(Device):
if os.path.exists(path): if os.path.exists(path):
# Delete the ebook # Delete the ebook
os.unlink(path) os.unlink(path)
try: if self.SUPPORTS_SUB_DIRS:
os.removedirs(os.path.dirname(path)) try:
except: os.removedirs(os.path.dirname(path))
pass except:
pass
@classmethod @classmethod
def remove_books_from_metadata(cls, paths, booklists): def remove_books_from_metadata(cls, paths, booklists):
@ -148,7 +149,18 @@ class USBMS(Device):
path = self.munge_path(path) path = self.munge_path(path)
src = open(path, 'rb') src = open(path, 'rb')
shutil.copyfileobj(src, outfile, 10*1024*1024) shutil.copyfileobj(src, outfile, 10*1024*1024)
def put_file(self, infile, path, replace_file=False, end_session=True):
path = self.munge_path(path)
if os.path.isdir(path):
path = os.path.join(path, infile.name)
if not replace_file and os.path.exists(path):
raise PathError('File already exists: ' + path)
dest = open(path, 'wb')
shutil.copyfileobj(infile, dest, 10*1024*1024)
dest.flush()
dest.close()
def munge_path(self, path): def munge_path(self, path):
if path.startswith('/') and not (path.startswith(self._main_prefix) or \ if path.startswith('/') and not (path.startswith(self._main_prefix) or \
(self._card_prefix and path.startswith(self._card_prefix))): (self._card_prefix and path.startswith(self._card_prefix))):
@ -157,6 +169,34 @@ class USBMS(Device):
path = path.replace('card:', self._card_prefix[:-1]) path = path.replace('card:', self._card_prefix[:-1])
return path return path
def list(self, path, recurse=False, end_session=True, munge=True):
if munge:
path = self.munge_path(path)
if os.path.isfile(path):
return [(os.path.dirname(path), [File(path)])]
entries = [File(os.path.join(path, f)) for f in os.listdir(path)]
dirs = [(path, entries)]
for _file in entries:
if recurse and _file.is_dir:
dirs[len(dirs):] = self.list(_file.path, recurse=True, munge=False)
return dirs
def mkdir(self, path, end_session=True):
if self.SUPPORTS_SUB_DIRS:
path = self.munge_path(path)
os.mkdir(path)
def rm(self, path, end_session=True):
path = self.munge_path(path)
self.delete_books([path])
def touch(self, path, end_session=True):
path = self.munge_path(path)
if not os.path.exists(path):
open(path, 'w').close()
if not os.path.isdir(path):
os.utime(path, None)
@classmethod @classmethod
def extract_book_metadata_by_filename(cls, filename): def extract_book_metadata_by_filename(cls, filename):
book_title = '' book_title = ''
@ -183,5 +223,3 @@ class USBMS(Device):
return book_title, book_author, book_mime return book_title, book_author, book_mime
# ls, rm, cp, mkdir, touch, cat