From f59bb9d2d405088a606729877759687bd90eb21a Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 16 Mar 2011 14:08:54 +0000 Subject: [PATCH] Add 'fixed' to check_library --- src/calibre/gui2/dialogs/check_library.py | 33 ++++++++++++++++++----- src/calibre/library/check_library.py | 2 +- src/calibre/library/database2.py | 15 ++++++----- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/calibre/gui2/dialogs/check_library.py b/src/calibre/gui2/dialogs/check_library.py index f9db87b087..560090d2b3 100644 --- a/src/calibre/gui2/dialogs/check_library.py +++ b/src/calibre/gui2/dialogs/check_library.py @@ -202,13 +202,19 @@ class CheckLibraryDialog(QDialog):
Delete marked is used to remove extra files/folders/covers that have no entries in the database. Check the box next to the item you want to delete. Use with caution.
-Fix marked is applicable only to covers (the two lines marked - 'fixable'). In the case of missing cover files, checking the fixable - box and pushing this button will remove the cover mark from the - database for all the files in that category. In the case of extra - cover files, checking the fixable box and pushing this button will - add the cover mark to the database for all the files in that - category.
+ +Fix marked is applicable only to covers and missing formats + (the three lines marked 'fixable'). In the case of missing cover files, + checking the fixable box and pushing this button will tell calibre that + there is no cover for all of the books listed. Use this option if you + are not going to restore the covers from a backup. In the case of extra + cover files, checking the fixable box and pushing this button will tell + calibre that the cover files it found are correct for all the books + listed. Use this when you are not going to delete the file(s). In the + case of missing formats, checking the fixable box and pushing this + button will tell calibre that the formats are really gone. Use this if + you are not going to restore the formats from a backup.
+ ''')) self.log = QTreeWidget(self) @@ -381,6 +387,19 @@ class CheckLibraryDialog(QDialog): unicode(it.text(1)))) self.run_the_check() + def fix_missing_formats(self): + tl = self.top_level_items['missing_formats'] + child_count = tl.childCount() + for i in range(0, child_count): + item = tl.child(i); + id = item.data(0, Qt.UserRole).toInt()[0] + all = self.db.formats(id, index_is_id=True, verify_formats=False) + all = set([f.strip() for f in all.split(',')]) if all else set() + valid = self.db.formats(id, index_is_id=True, verify_formats=True) + valid = set([f.strip() for f in valid.split(',')]) if valid else set() + for fmt in all-valid: + self.db.remove_format(id, fmt, index_is_id=True, db_only=True) + def fix_missing_covers(self): tl = self.top_level_items['missing_covers'] child_count = tl.childCount() diff --git a/src/calibre/library/check_library.py b/src/calibre/library/check_library.py index 19ecb97308..6013c76b9c 100644 --- a/src/calibre/library/check_library.py +++ b/src/calibre/library/check_library.py @@ -27,7 +27,7 @@ CHECKS = [('invalid_titles', _('Invalid titles'), True, False), ('extra_titles', _('Extra titles'), True, False), ('invalid_authors', _('Invalid authors'), True, False), ('extra_authors', _('Extra authors'), True, False), - ('missing_formats', _('Missing book formats'), False, False), + ('missing_formats', _('Missing book formats'), False, True), ('extra_formats', _('Extra book formats'), True, False), ('extra_files', _('Unknown files in books'), True, False), ('missing_covers', _('Missing covers files'), False, True), diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index e70a746b15..ec766c72f3 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1154,15 +1154,18 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): if notify: self.notify('delete', [id]) - def remove_format(self, index, format, index_is_id=False, notify=True, commit=True): + def remove_format(self, index, format, index_is_id=False, notify=True, + commit=True, db_only=False): id = index if index_is_id else self.id(index) name = self.conn.get('SELECT name FROM data WHERE book=? AND format=?', (id, format), all=False) if name: - path = self.format_abspath(id, format, index_is_id=True) - try: - delete_file(path) - except: - traceback.print_exc() + if not db_only: + try: + path = self.format_abspath(id, format, index_is_id=True) + if path: + delete_file(path) + except: + traceback.print_exc() self.conn.execute('DELETE FROM data WHERE book=? AND format=?', (id, format.upper())) if commit: self.conn.commit()