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
|
from calibre.utils.logging import Log
|
||||||
|
|
||||||
class NoSupportedInputFormats(Exception):
|
class NoSupportedInputFormats(Exception):
|
||||||
pass
|
|
||||||
|
def __init__(self, available_formats):
|
||||||
|
Exception.__init__(self)
|
||||||
|
self.available_formats = available_formats
|
||||||
|
|
||||||
def sort_formats_by_preference(formats, prefs):
|
def sort_formats_by_preference(formats, prefs):
|
||||||
uprefs = [x.upper() for x in 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 = set([x.lower() for x in supported_input_formats()])
|
||||||
input_formats = sorted(available_formats.intersection(input_formats))
|
input_formats = sorted(available_formats.intersection(input_formats))
|
||||||
if not input_formats:
|
if not input_formats:
|
||||||
raise NoSupportedInputFormats
|
raise NoSupportedInputFormats(tuple(x for x in available_formats if x))
|
||||||
return input_formats
|
return input_formats
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,20 +88,35 @@ def convert_single_ebook(parent, db, book_ids, auto_conversion=False, # {{{
|
|||||||
|
|
||||||
changed = True
|
changed = True
|
||||||
d.break_cycles()
|
d.break_cycles()
|
||||||
except NoSupportedInputFormats:
|
except NoSupportedInputFormats as nsif:
|
||||||
bad.append(book_id)
|
bad.append((book_id, nsif.available_formats))
|
||||||
|
|
||||||
if bad and show_no_format_warning:
|
if bad and show_no_format_warning:
|
||||||
res = []
|
if len(bad) == 1 and not bad[0][1]:
|
||||||
for id in bad:
|
title = db.title(bad[0][0], True)
|
||||||
title = db.title(id, True)
|
warning_dialog(parent, _('Could not convert'), '<p>'+
|
||||||
res.append('%s'%title)
|
_('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, available_formats in bad:
|
||||||
|
title = db.title(id, True)
|
||||||
|
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'),
|
msg = '%s' % '\n'.join(res)
|
||||||
_('Could not convert %(num)d of %(tot)d books, because no suitable source'
|
warning_dialog(parent, _('Could not convert some books'),
|
||||||
' format was found.') % dict(num=len(res), tot=total),
|
_('Could not convert %(num)d of %(tot)d books, because no supported source'
|
||||||
msg).exec_()
|
' formats were found.') % dict(num=len(res), tot=total),
|
||||||
|
msg).exec_()
|
||||||
|
|
||||||
return jobs, changed, bad
|
return jobs, changed, bad
|
||||||
# }}}
|
# }}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user