From 0cd76baa1bfb746920ce00960d08c6e903ef8f31 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 6 Jul 2014 14:10:24 +0530 Subject: [PATCH] Nicer error message when failing to edit EPUB file with missing obfuscation key --- src/calibre/ebooks/oeb/polish/container.py | 5 ++++- src/calibre/gui2/tweak_book/boss.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index d9175b6bd2..44a876a18b 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -893,6 +893,9 @@ class Container(object): # {{{ class InvalidEpub(InvalidBook): pass +class ObfuscationKeyMissing(InvalidEpub): + pass + OCF_NS = 'urn:oasis:names:tc:opendocument:xmlns:container' class EpubContainer(Container): @@ -1071,7 +1074,7 @@ class EpubContainer(Container): for font, alg in fonts.iteritems(): tkey = key if alg == ADOBE_OBFUSCATION else idpf_key if not tkey: - raise InvalidBook('Failed to find obfuscation key') + raise ObfuscationKeyMissing('Failed to find obfuscation key') raw = self.raw_data(font, decode=False) raw = decrypt_font_data(tkey, raw, alg) with self.open(font, 'wb') as f: diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 2265f268e7..6f24a75a41 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -256,6 +256,11 @@ class Boss(QObject): if 'DRMError:' in job.traceback: from calibre.gui2.dialogs.drm_error import DRMErrorMessage return DRMErrorMessage(self.gui).exec_() + if 'ObfuscationKeyMissing:' in job.traceback: + return error_dialog(self.gui, _('Failed to open book'), _( + 'Failed to open book, it has obfuscated fonts, but the obfuscation key is missing from the OPF.' + ' Do an EPUB to EPUB conversion before trying to edit this book.'), show=True) + return error_dialog(self.gui, _('Failed to open book'), _('Failed to open book, click Show details for more information.'), det_msg=job.traceback, show=True)