From 32d347ea73665ff0a3fd2a2db92e171c4d86fc44 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 27 Feb 2014 12:52:34 +0530 Subject: [PATCH] Edit Book: When editing EPUB files, and a file is added in META-INF/ do not automatically add it to the manifest. Also do not warn about unmanifested files inside META-INF/ since a few vendors (Apple) require non standard files in that location. Fixes #1283015 [com.apple.ibooks.display-options.xml](https://bugs.launchpad.net/calibre/+bug/1283015) --- src/calibre/ebooks/oeb/polish/check/links.py | 29 +++++++++++++------- src/calibre/ebooks/oeb/polish/container.py | 8 +++++- src/calibre/gui2/tweak_book/file_list.py | 3 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/check/links.py b/src/calibre/ebooks/oeb/polish/check/links.py index 8ea0d25194..abb80e856c 100644 --- a/src/calibre/ebooks/oeb/polish/check/links.py +++ b/src/calibre/ebooks/oeb/polish/check/links.py @@ -98,20 +98,27 @@ class Unmanifested(BadLink): def __init__(self, name): BadLink.__init__(self, _( 'The file %s is not listed in the manifest') % name, name) - if name == 'META-INF/calibre_bookmarks.txt': - self.HELP = _( - 'This file stores the bookmarks and last opened information from' - ' the calibre ebook viewer. You can remove it if you do not' - ' need that information, or dont want to share it with' - ' other people you send this book to.') - self.INDIVIDUAL_FIX = _('Remove this file') - self.level = INFO - self.msg = _('The bookmarks file used by the calibre ebook viewer is present') + + +class Bookmarks(BadLink): + + HELP = _( + 'This file stores the bookmarks and last opened information from' + ' the calibre ebook viewer. You can remove it if you do not' + ' need that information, or dont want to share it with' + ' other people you send this book to.') + INDIVIDUAL_FIX = _('Remove this file') + level = INFO + + def __init__(self, name): + BadLink.__init__(self, _( + 'The bookmarks file used by the calibre ebook viewer is present'), name) def __call__(self, container): container.remove_item(self.name) return True + class MimetypeMismatch(BaseError): level = WARN @@ -243,7 +250,9 @@ def check_links(container): manifest_names = set(container.manifest_id_map.itervalues()) for name in container.mime_map: - if name not in container.names_that_need_not_be_manifested and name not in manifest_names: + if name not in manifest_names and not container.ok_to_be_unmanifested(name): a(Unmanifested(name)) + if name == 'META-INF/calibre_bookmarks.txt': + a(Bookmarks(name)) return errors diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index 5910b85a0b..092bc174d2 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -192,7 +192,7 @@ class Container(object): # {{{ mt = media_type or self.guess_type(name) self.name_path_map[name] = path self.mime_map[name] = mt - if name in self.names_that_need_not_be_manifested: + if self.ok_to_be_unmanifested(name): return all_ids = {x.get('id') for x in self.opf_xpath('//*[@id]')} c = 0 @@ -386,6 +386,9 @@ class Container(object): # {{{ data, self.used_encoding = xml_to_unicode(data) return fix_data(data) + def ok_to_be_unmanifested(self, name): + return name in self.names_that_need_not_be_manifested + @property def names_that_need_not_be_manifested(self): return {self.opf_name} @@ -888,6 +891,9 @@ class EpubContainer(Container): def names_that_need_not_be_manifested(self): return super(EpubContainer, self).names_that_need_not_be_manifested | {'META-INF/' + x for x in self.META_INF} + def ok_to_be_unmanifested(self, name): + return name in self.names_that_need_not_be_manifested or name.startswith('META-INF/') + @property def names_that_must_not_be_removed(self): return super(EpubContainer, self).names_that_must_not_be_removed | {'META-INF/container.xml'} diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 54c57ff510..cf3166aa92 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -339,7 +339,6 @@ class FileList(QTreeWidget): icon = self.rendered_emblem_cache[emblems] = canvas item.setData(0, Qt.DecorationRole, icon) - ok_to_be_unmanifested = container.names_that_need_not_be_manifested cannot_be_renamed = container.names_that_must_not_be_changed ncx_mime = guess_type('a.ncx') @@ -371,7 +370,7 @@ class FileList(QTreeWidget): if imt == ncx_mime: emblems.append('toc.png') tooltips.append(_('This file contains the metadata table of contents')) - if name not in manifested_names and name not in ok_to_be_unmanifested: + if name not in manifested_names and not container.ok_to_be_unmanifested(name): emblems.append('dialog_question.png') tooltips.append(_('This file is not listed in the book manifest')) if linear is False: