mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Nicer error message when no supported formats for conversion found
This commit is contained in:
parent
7e0acebabc
commit
f368250f1d
@ -33,7 +33,10 @@ from calibre.utils.config import prefs
|
||||
from calibre.utils.logging import Log
|
||||
|
||||
class NoSupportedInputFormats(Exception):
|
||||
pass
|
||||
|
||||
def __init__(self, available_formats):
|
||||
Exception.__init__(self)
|
||||
self.available_formats = available_formats
|
||||
|
||||
def sort_formats_by_preference(formats, prefs):
|
||||
uprefs = [x.upper() for x in prefs]
|
||||
@ -86,7 +89,7 @@ def get_supported_input_formats_for_book(db, book_id):
|
||||
input_formats = set([x.lower() for x in supported_input_formats()])
|
||||
input_formats = sorted(available_formats.intersection(input_formats))
|
||||
if not input_formats:
|
||||
raise NoSupportedInputFormats
|
||||
raise NoSupportedInputFormats(tuple(x for x in available_formats if x))
|
||||
return input_formats
|
||||
|
||||
|
||||
|
@ -88,19 +88,34 @@ def convert_single_ebook(parent, db, book_ids, auto_conversion=False, # {{{
|
||||
|
||||
changed = True
|
||||
d.break_cycles()
|
||||
except NoSupportedInputFormats:
|
||||
bad.append(book_id)
|
||||
except NoSupportedInputFormats as nsif:
|
||||
bad.append((book_id, nsif.available_formats))
|
||||
|
||||
if bad and show_no_format_warning:
|
||||
if len(bad) == 1 and not bad[0][1]:
|
||||
title = db.title(bad[0][0], True)
|
||||
warning_dialog(parent, _('Could not convert'), '<p>'+
|
||||
_('Could not convert <b>%s</b> as it has no ebook files. If you '
|
||||
'think it should have files, but calibre is not finding '
|
||||
'them, that is most likely because you moved the book\'s '
|
||||
'files around outside of calibre. You will need to find those files '
|
||||
'and re-add them to calibre.')%title, show=True)
|
||||
else:
|
||||
res = []
|
||||
for id in bad:
|
||||
for id, available_formats in bad:
|
||||
title = db.title(id, True)
|
||||
res.append('%s'%title)
|
||||
if available_formats:
|
||||
msg = _('No supported formats (Available formats: %s)')%(
|
||||
', '.join(available_formats))
|
||||
else:
|
||||
msg = _('This book has no actual ebook files')
|
||||
res.append('%s - %s'%(title, msg))
|
||||
|
||||
|
||||
msg = '%s' % '\n'.join(res)
|
||||
warning_dialog(parent, _('Could not convert some books'),
|
||||
_('Could not convert %(num)d of %(tot)d books, because no suitable source'
|
||||
' format was found.') % dict(num=len(res), tot=total),
|
||||
_('Could not convert %(num)d of %(tot)d books, because no supported source'
|
||||
' formats were found.') % dict(num=len(res), tot=total),
|
||||
msg).exec_()
|
||||
|
||||
return jobs, changed, bad
|
||||
|
Loading…
x
Reference in New Issue
Block a user