diff --git a/src/calibre/gui2/preferences/misc.py b/src/calibre/gui2/preferences/misc.py index eae79fdfc0..e749a6fb98 100644 --- a/src/calibre/gui2/preferences/misc.py +++ b/src/calibre/gui2/preferences/misc.py @@ -88,10 +88,16 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): r('enforce_cpu_limit', config, restart_required=True) self.device_detection_button.clicked.connect(self.debug_device_detection) self.compact_button.clicked.connect(self.compact) + self.button_all_books_dirty.clicked.connect(self.mark_dirty) self.button_open_config_dir.clicked.connect(self.open_config_dir) self.button_osx_symlinks.clicked.connect(self.create_symlinks) self.button_osx_symlinks.setVisible(isosx) + def mark_dirty(self): + db = self.gui.library_view.model().db + ids = [id for id in db.data.iterallids()] + db.dirtied(ids) + def debug_device_detection(self, *args): from calibre.gui2.preferences.device_debug import DebugDevice d = DebugDevice(self) diff --git a/src/calibre/gui2/preferences/misc.ui b/src/calibre/gui2/preferences/misc.ui index f8582a3675..573c61aba5 100644 --- a/src/calibre/gui2/preferences/misc.ui +++ b/src/calibre/gui2/preferences/misc.ui @@ -124,7 +124,14 @@ - + + + + Force saving metadata of all books + + + + Qt::Vertical @@ -132,7 +139,7 @@ 20 - 18 + 1000 diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index cdf0c1fce6..9d6f87324f 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -44,6 +44,7 @@ class MetadataBackup(Thread): # {{{ self.keep_running = False def run(self): + import traceback while self.keep_running: try: time.sleep(0.5) # Limit to two per second @@ -53,11 +54,11 @@ class MetadataBackup(Thread): # {{{ except: # Happens during interpreter shutdown break + try: path, mi = self.get_metadata_for_dump(id_) except: prints('Failed to get backup metadata for id:', id_, 'once') - import traceback traceback.print_exc() time.sleep(2) try: @@ -67,6 +68,10 @@ class MetadataBackup(Thread): # {{{ traceback.print_exc() continue + if mi is None: + self.clear_dirtied([id_]) + continue + # Give the GUI thread a chance to do something. Python threads don't # have priorities, so this thread would naturally keep the processor # until some scheduling event happens. The sleep makes such an event diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 0943c86e43..6f628d8454 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -657,8 +657,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.dirtied(book_ids) def get_metadata_for_dump(self, idx): - path = os.path.join(self.abspath(idx, index_is_id=True), 'metadata.opf') - mi = self.get_metadata(idx, index_is_id=True) + try: + path = os.path.join(self.abspath(idx, index_is_id=True), 'metadata.opf') + mi = self.get_metadata(idx, index_is_id=True) + except: + return ((None, None)) return ((path, mi)) def get_metadata(self, idx, index_is_id=False, get_cover=False):