IGN:USBMS driver cleanups

This commit is contained in:
Kovid Goyal 2009-01-12 08:58:03 -08:00
commit 7af0e4b7fc
5 changed files with 33 additions and 25 deletions

View File

@ -9,16 +9,9 @@ import os, fnmatch
from calibre.devices.usbms.driver import USBMS from calibre.devices.usbms.driver import USBMS
class CYBOOKG3(USBMS): class CYBOOKG3(USBMS):
MIME_MAP = {
'mobi' : 'application/mobi',
'prc' : 'application/prc',
'html' : 'application/html',
'pdf' : 'application/pdf',
'rtf' : 'application/rtf',
'txt' : 'text/plain',
}
# Ordered list of supported formats # Ordered list of supported formats
FORMATS = MIME_MAP.keys() # Be sure these have an entry in calibre.devices.mime
FORMATS = ['mobi', 'prc', 'html', 'pdf', 'rtf', 'txt']
VENDOR_ID = 0x0bda VENDOR_ID = 0x0bda
PRODUCT_ID = 0x0703 PRODUCT_ID = 0x0703

View File

@ -9,14 +9,8 @@ import os, fnmatch
from calibre.devices.usbms.driver import USBMS from calibre.devices.usbms.driver import USBMS
class KINDLE(USBMS): class KINDLE(USBMS):
MIME_MAP = {
'azw' : 'application/azw',
'mobi' : 'application/mobi',
'prc' : 'application/prc',
'txt' : 'text/plain',
}
# Ordered list of supported formats # Ordered list of supported formats
FORMATS = MIME_MAP.keys() FORMATS = ['azw', 'mobi', 'prc', 'txt']
VENDOR_ID = 0x1949 VENDOR_ID = 0x1949
PRODUCT_ID = 0x0001 PRODUCT_ID = 0x0001

View File

@ -0,0 +1,19 @@
__license__ = 'GPL v3'
__copyright__ = '2009, John Schember <john at nachtimwald.com>'
'''
Global Mime mapping of ebook types.
'''
MIME_MAP = {
'azw' : 'application/azw',
'epub' : 'application/epub+zip',
'html' : 'text/html',
'lrf' : 'application/x-sony-bbeb',
'lrx' : 'application/x-sony-bbeb',
'mobi' : 'application/mobi',
'pdf' : 'application/pdf',
'prc' : 'application/prc',
'rtf' : 'application/rtf',
'txt' : 'text/plain',
}

View File

@ -6,7 +6,7 @@ intended to be subclassed with the relevant parts implemented for a particular
device. This class handles devive detection. device. This class handles devive detection.
''' '''
import os, time import os, subprocess, time
from calibre.devices.interface import Device as _Device from calibre.devices.interface import Device as _Device
from calibre.devices.errors import DeviceError from calibre.devices.errors import DeviceError
@ -150,13 +150,14 @@ class Device(_Device):
return (msz, 0, csz) return (msz, 0, csz)
def windows_match_device(self, pnp_id, device_id): def windows_match_device(self, pnp_id, device_id):
pnp_id = pnp_id.upper()
if device_id and pnp_id is not None: if device_id and pnp_id is not None:
pnp_id = pnp_id.upper()
device_id = device_id.upper() device_id = device_id.upper()
if 'VEN_' + self.VENDOR_NAME in pnp_id and 'PROD_' + device_id in pnp_id: if 'VEN_' + self.VENDOR_NAME in pnp_id and 'PROD_' + device_id in pnp_id:
return True return True
return False return False
def windows_get_drive_prefix(self, drive): def windows_get_drive_prefix(self, drive):

View File

@ -12,11 +12,11 @@ from itertools import cycle
from calibre.devices.usbms.device import Device from calibre.devices.usbms.device import Device
from calibre.devices.usbms.books import BookList, Book from calibre.devices.usbms.books import BookList, Book
from calibre.devices.errors import FreeSpaceError from calibre.devices.errors import FreeSpaceError
from calibre.devices.mime import MIME_MAP
class USBMS(Device): class USBMS(Device):
EBOOK_DIR_MAIN = '' EBOOK_DIR_MAIN = ''
EBOOK_DIR_CARD = '' EBOOK_DIR_CARD = ''
MIME_MAP = {}
FORMATS = [] FORMATS = []
def __init__(self, key='-1', log_packets=False, report_progress=None): def __init__(self, key='-1', log_packets=False, report_progress=None):
@ -41,7 +41,7 @@ class USBMS(Device):
# Get all books in all directories under the root ebook_dir directory # Get all books in all directories under the root ebook_dir directory
for path, dirs, files in os.walk(os.path.join(prefix, ebook_dir)): for path, dirs, files in os.walk(os.path.join(prefix, ebook_dir)):
# Filter out anything that isn't in the list of supported ebook types # Filter out anything that isn't in the list of supported ebook types
for book_type in self.MIME_MAP.keys(): for book_type in self.FORMATS:
for filename in fnmatch.filter(files, '*.%s' % (book_type)): for filename in fnmatch.filter(files, '*.%s' % (book_type)):
title, author, mime = self.__class__.extract_book_metadata_by_filename(filename) title, author, mime = self.__class__.extract_book_metadata_by_filename(filename)
@ -138,10 +138,11 @@ class USBMS(Device):
else: else:
book_title = os.path.splitext(filename)[0].replace('_', ' ') book_title = os.path.splitext(filename)[0].replace('_', ' ')
fileext = os.path.splitext(filename)[1] fileext = os.path.splitext(filename)[1][1:]
if fileext in cls.MIME_MAP.keys():
book_mime = cls.MIME_MAP[fileext] if fileext in cls.FORMATS:
book_mime = MIME_MAP[fileext] if fileext in MIME_MAP.keys() else 'Unknown'
return book_title, book_author, book_mime return book_title, book_author, book_mime
# ls, rm, cp, mkdir, touch, cat # ls, rm, cp, mkdir, touch, cat