Improved error reporting for comic conversion

This commit is contained in:
Kovid Goyal 2009-12-21 11:14:49 -07:00
parent 033de33a99
commit 480da4436f
2 changed files with 9 additions and 5 deletions

View File

@ -8,6 +8,7 @@ Based on ideas from comiclrf created by FangornUK.
''' '''
import os, shutil, traceback, textwrap, time import os, shutil, traceback, textwrap, time
from ctypes import byref
from Queue import Empty from Queue import Empty
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
@ -75,7 +76,10 @@ class PageProcessor(list):
if img < 0: if img < 0:
raise RuntimeError('Cannot create wand.') raise RuntimeError('Cannot create wand.')
if not pw.MagickReadImage(img, self.path_to_page): if not pw.MagickReadImage(img, self.path_to_page):
raise IOError('Failed to read image from: %'%self.path_to_page) severity = pw.ExceptionType(0)
msg = pw.MagickGetException(img, byref(severity))
raise IOError('Failed to read image from: %s: %s'
%(self.path_to_page, msg))
width = pw.MagickGetImageWidth(img) width = pw.MagickGetImageWidth(img)
height = pw.MagickGetImageHeight(img) height = pw.MagickGetImageHeight(img)
if self.num == 0: # First image so create a thumbnail from it if self.num == 0: # First image so create a thumbnail from it
@ -363,14 +367,14 @@ class ComicInput(InputFormatPlugin):
else: else:
new_pages, failures = process_pages(new_pages, self.opts, new_pages, failures = process_pages(new_pages, self.opts,
self.report_progress, tdir2) self.report_progress, tdir2)
if not new_pages:
raise ValueError('Could not find any valid pages in comic: %s'
% comic)
if failures: if failures:
self.log.warning('Could not process the following pages ' self.log.warning('Could not process the following pages '
'(run with --verbose to see why):') '(run with --verbose to see why):')
for f in failures: for f in failures:
self.log.warning('\t', f) self.log.warning('\t', f)
if not new_pages:
raise ValueError('Could not find any valid pages in comic: %s'
% comic)
thumbnail = os.path.join(tdir2, thumbnail = os.path.join(tdir2,
'thumbnail.'+self.opts.output_format.lower()) 'thumbnail.'+self.opts.output_format.lower())
if not os.access(thumbnail, os.R_OK): if not os.access(thumbnail, os.R_OK):

View File

@ -828,7 +828,7 @@ else:
IsMagickWand = _magick.IsMagickWand IsMagickWand = _magick.IsMagickWand
# MagickGetException # MagickGetException
try: try:
_magick.MagickGetException.restype = ctypes.POINTER(ctypes.c_char) _magick.MagickGetException.restype = ctypes.c_char_p
_magick.MagickGetException.argtypes = (MagickWand,ctypes.POINTER(ExceptionType)) _magick.MagickGetException.argtypes = (MagickWand,ctypes.POINTER(ExceptionType))
except AttributeError,e: except AttributeError,e:
pass pass