Add 'fixed' to check_library

This commit is contained in:
Charles Haley 2011-03-16 14:08:54 +00:00
parent 0994495bec
commit f59bb9d2d4
3 changed files with 36 additions and 14 deletions

View File

@ -202,13 +202,19 @@ class CheckLibraryDialog(QDialog):
<p><i>Delete marked</i> 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.</p>
<p><i>Fix marked</i> 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.</p>
<p><i>Fix marked</i> 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.</p>
'''))
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()

View File

@ -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),

View File

@ -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()