Fix drive order detection on windows for Cybook. ALso fix regression in comic comversion.

This commit is contained in:
Kovid Goyal 2009-01-10 16:12:17 -08:00
commit 329447ac57
6 changed files with 68 additions and 49 deletions

View File

@ -25,15 +25,16 @@ class CYBOOKG3(USBMS):
BCD = [0x110, 0x132]
VENDOR_NAME = 'BOOKEEN'
PRODUCT_NAME = 'CYBOOK_GEN3'
WINDOWS_MAIN_MEM = 'CYBOOK_GEN3__-FD'
WINDOWS_CARD_MEM = 'CYBOOK_GEN3__-SD'
OSX_NAME_MAIN_MEM = 'Bookeen Cybook Gen3 -FD Media'
OSX_NAME_CARD_MEM = 'Bookeen Cybook Gen3 -SD Media'
OSX_MAIN_MEM = 'Bookeen Cybook Gen3 -FD Media'
OSX_CARD_MEM = 'Bookeen Cybook Gen3 -SD Media'
MAIN_MEMORY_VOLUME_LABEL = 'Cybook Gen 3 Main Memory'
STORAGE_CARD_VOLUME_LABEL = 'Cybook Gen 3 Storage Card'
EBOOK_DIR = "eBooks"
EBOOK_DIR_MAIN = "eBooks"
def delete_books(self, paths, end_session=True):
for path in paths:

View File

@ -20,13 +20,25 @@ class KINDLE(USBMS):
VENDOR_ID = 0x1949
PRODUCT_ID = 0x0001
BCD = 0x399
BCD = [0x399]
VENDOR_NAME = 'AMAZON'
PRODUCT_NAME = 'KINDLE'
WINDOWS_MAIN_MEM = 'KINDLE'
MAIN_MEMORY_VOLUME_LABEL = 'Kindle Main Memory'
STORAGE_CARD_VOLUME_LABEL = 'Kindle Storage Card'
EBOOK_DIR = "documents"
EBOOK_DIR_MAIN = "documents"
def delete_books(self, paths, end_session=True):
for path in paths:
if os.path.exists(path):
os.unlink(path)
filepath, ext = os.path.splitext(path)
basepath, filename = os.path.split(filepath)
# Delete the ebook auxiliary file
if os.path.exists(filepath + '.mbp'):
os.unlink(filepath + '.mbp')

View File

@ -23,11 +23,12 @@ class Device(_Device):
PRODUCT_ID = 0x0
BCD = None
VENDOR_NAME = ''
PRODUCT_NAME = ''
VENDOR_NAME = None
WINDOWS_MAIN_MEM = None
WINDOWS_CARD_MEM = None
OSX_NAME_MAIN_MEM = ''
OSX_NAME_CARD_MEM = ''
OSX_MAIN_MEM = None
OSX_CARD_MEM = None
MAIN_MEMORY_VOLUME_LABEL = ''
STORAGE_CARD_VOLUME_LABEL = ''
@ -148,43 +149,46 @@ class Device(_Device):
return (msz, 0, csz)
@classmethod
def windows_match_device(cls, device_id):
def windows_match_device(self, pnp_id, device_id):
if device_id and pnp_id is not None:
pnp_id = pnp_id.upper()
device_id = device_id.upper()
if 'VEN_'+cls.VENDOR_NAME in device_id and \
'PROD_'+cls.PRODUCT_NAME in device_id:
return True
vid, pid = hex(cls.VENDOR_ID)[2:], hex(cls.PRODUCT_ID)[2:]
while len(vid) < 4: vid = '0' + vid
while len(pid) < 4: pid = '0' + pid
if 'VID_'+vid in device_id and 'PID_'+pid in device_id:
if 'VEN_' + self.VENDOR_NAME in pnp_id and 'PROD_' + device_id in pnp_id:
return True
return False
# This only supports Windows >= 2000
def open_windows(self):
drives = []
wmi = __import__('wmi', globals(), locals(), [], -1)
c = wmi.WMI()
for drive in c.Win32_DiskDrive():
if self.__class__.windows_match_device(str(drive.PNPDeviceID)):
if drive.Partitions == 0:
continue
def windows_get_drive_prefix(self, drive):
prefix = None
try:
partition = drive.associators("Win32_DiskDriveToDiskPartition")[0]
logical_disk = partition.associators('Win32_LogicalDiskToPartition')[0]
prefix = logical_disk.DeviceID + os.sep
drives.append((drive.Index, prefix))
except IndexError:
continue
pass
return prefix
def open_windows(self):
drives = {}
wmi = __import__('wmi', globals(), locals(), [], -1)
c = wmi.WMI()
for drive in c.Win32_DiskDrive():
if self.windows_match_device(str(drive.PNPDeviceID), WINDOWS_MAIN_MEM):
drives['main'] = self.windows_get_drive_prefix(drive)
else if self.windows_match_device(str(drive.PNPDeviceID), WINDOWS_CARD_MEM):
drives['card'] = self.windows_get_drive_prefix(drive)
if 'main' and 'card' in drives.keys():
break
if not drives:
raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.') % self.__class__.__name__)
drives.sort(cmp=lambda a, b: cmp(a[0], b[0]))
self._main_prefix = drives[0][1]
if len(drives) > 1:
self._card_prefix = drives[1][1]
self._main_prefix = drives['main'] if 'main' in names.keys() else None
self._card_prefix = drives['card'] if 'card' in names.keys() else None
@classmethod
def get_osx_mountpoints(self, raw=None):
@ -207,9 +211,9 @@ class Device(_Device):
break
for i, line in enumerate(lines):
if line.strip().endswith('<class IOMedia>') and self.OSX_NAME_MAIN_MEM in line:
if self.OSX_MAIN_MEM is not None and line.strip().endswith('<class IOMedia>') and self.OSX_MAIN_MEM in line:
get_dev_node(lines[i+1:], 'main')
if line.strip().endswith('<class IOMedia>') and self.OSX_NAME_CARD_MEM in line:
if self.OSX_CARD_MEM is not None and line.strip().endswith('<class IOMedia>') and self.OSX_CARD_MEM in line:
get_dev_node(lines[i+1:], 'card')
if len(names.keys()) == 2:
break

View File

@ -14,7 +14,8 @@ from calibre.devices.usbms.books import BookList, Book
from calibre.devices.errors import FreeSpaceError
class USBMS(Device):
EBOOK_DIR = ''
EBOOK_DIR_MAIN = ''
EBOOK_DIR_CARD = ''
MIME_MAP = {}
FORMATS = []
@ -35,9 +36,10 @@ class USBMS(Device):
return bl
prefix = self._card_prefix if oncard else self._main_prefix
ebook_dir = self.EBOOK_DIR_CARD if oncard else self.EBOOK_DIR_MAIN
# Get all books in all directories under the root EBOOK_DIR directory
for path, dirs, files in os.walk(os.path.join(prefix, self.EBOOK_DIR)):
# 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)):
# Filter out anything that isn't in the list of supported ebook types
for book_type in self.MIME_MAP.keys():
for filename in fnmatch.filter(files, '*.%s' % (book_type)):
@ -51,9 +53,9 @@ class USBMS(Device):
raise ValueError(_('The reader has no storage card connected.'))
if not on_card:
path = os.path.join(self._main_prefix, self.EBOOK_DIR)
path = os.path.join(self._main_prefix, self.EBOOK_DIR_MAIN)
else:
path = os.path.join(self._card_prefix, self.EBOOK_DIR)
path = os.path.join(self._card_prefix, self.EBOOK_DIR_CARD)
sizes = map(os.path.getsize, files)
size = sum(sizes)

View File

@ -560,7 +560,7 @@ class Processor(Parser):
hr = etree.Element('hr')
if elem.getprevious() is None:
elem.getparent()[:0] = [hr]
else:
elif elem.getparent() is not None:
insert = None
for i, c in enumerate(elem.getparent()):
if c is elem:

View File

@ -425,7 +425,7 @@ def do_convert(path_to_file, opts, notification=lambda m, p: p, output_format='l
thumbnail = None
if not pages:
raise ValueError('Could not find any pages in the comic: %s'%source)
if not opts.no_process:
if not getattr(opts, 'no_process', False):
pages, failures, tdir2 = process_pages(pages, opts, notification)
if not pages:
raise ValueError('Could not find any valid pages in the comic: %s'%source)