mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
When adding books, if reading metadata raises an exception, make error reporting more robust
This commit is contained in:
parent
a9f3765632
commit
61850df263
@ -24,6 +24,7 @@ def read_metadata_(task, tdir, notification=lambda x,y:x):
|
||||
from calibre.ebooks.metadata.meta import metadata_from_formats
|
||||
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||
for x in task:
|
||||
try:
|
||||
id, formats = x
|
||||
if isinstance(formats, basestring): formats = [formats]
|
||||
mi = metadata_from_formats(formats)
|
||||
@ -39,6 +40,10 @@ def read_metadata_(task, tdir, notification=lambda x,y:x):
|
||||
with open(os.path.join(tdir, str(id)), 'wb') as f:
|
||||
f.write(cdata)
|
||||
notification(0.5, id)
|
||||
except:
|
||||
import traceback
|
||||
with open(os.path.join(tdir, '%s.error'%id), 'wb') as f:
|
||||
f.write(traceback.format_exc())
|
||||
|
||||
class Progress(object):
|
||||
|
||||
@ -49,7 +54,10 @@ class Progress(object):
|
||||
def __call__(self, id):
|
||||
cover = os.path.join(self.tdir, str(id))
|
||||
if not os.path.exists(cover): cover = None
|
||||
self.result_queue.put((id, os.path.join(self.tdir, '%s.opf'%id), cover))
|
||||
res = os.path.join(self.tdir, '%s.error'%id)
|
||||
if not os.path.exists(res):
|
||||
res = res.replace('.error', '.opf')
|
||||
self.result_queue.put((id, res, cover))
|
||||
|
||||
class ReadMetadata(Thread):
|
||||
|
||||
|
@ -44,6 +44,7 @@ class Adder(QObject):
|
||||
self.pd = ProgressDialog(_('Adding...'), parent=parent)
|
||||
self.spare_server = spare_server
|
||||
self.db = db
|
||||
self.critical = {}
|
||||
self.pd.setModal(True)
|
||||
self.pd.show()
|
||||
self._parent = parent
|
||||
@ -123,8 +124,12 @@ class Adder(QObject):
|
||||
return
|
||||
self.pd.value += 1
|
||||
formats = self.ids.pop(id)
|
||||
mi = MetaInformation(OPF(opf))
|
||||
name = self.nmap.pop(id)
|
||||
if opf.endswith('.error'):
|
||||
mi = MetaInformation('', [_('Unknown')])
|
||||
self.critical[name] = open(opf, 'rb').read().decode('utf-8', 'replace')
|
||||
else:
|
||||
mi = MetaInformation(OPF(opf))
|
||||
if not mi.title:
|
||||
mi.title = os.path.splitext(name)[0]
|
||||
mi.title = mi.title if isinstance(mi.title, unicode) else \
|
||||
|
@ -860,6 +860,13 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
self.library_view.model().books_added(self._adder.number_of_books_added)
|
||||
if hasattr(self, 'db_images'):
|
||||
self.db_images.reset()
|
||||
if self._adder.critical:
|
||||
det_msg = []
|
||||
for name, log in self._adder.critical.items():
|
||||
det_msg.append(name+'\n'+log)
|
||||
error_dialog(self, _('Failed to read metadata'),
|
||||
_('Failed to read metadata from the following')+':',
|
||||
det_msg='\n\n'.join(det_msg), show=True)
|
||||
|
||||
self._adder = None
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user