mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
check_library: check for formats & covers in db for book directories that are gone. Also incorrect path for missing covers when the book directory was still there, and some identifier names.
This commit is contained in:
parent
16c81b450d
commit
ce26007ad3
@ -47,8 +47,8 @@ class CheckLibrary(object):
|
|||||||
self.is_case_sensitive = db.is_case_sensitive
|
self.is_case_sensitive = db.is_case_sensitive
|
||||||
|
|
||||||
self.all_authors = frozenset([x[1] for x in db.all_authors()])
|
self.all_authors = frozenset([x[1] for x in db.all_authors()])
|
||||||
self.all_ids = frozenset([id for id in db.all_ids()])
|
self.all_ids = frozenset([id_ for id_ in db.all_ids()])
|
||||||
self.all_dbpaths = frozenset(self.dbpath(id) for id in self.all_ids)
|
self.all_dbpaths = frozenset(self.dbpath(id_) for id_ in self.all_ids)
|
||||||
self.all_lc_dbpaths = frozenset([f.lower() for f in self.all_dbpaths])
|
self.all_lc_dbpaths = frozenset([f.lower() for f in self.all_dbpaths])
|
||||||
|
|
||||||
self.db_id_regexp = re.compile(r'^.* \((\d+)\)$')
|
self.db_id_regexp = re.compile(r'^.* \((\d+)\)$')
|
||||||
@ -73,8 +73,8 @@ class CheckLibrary(object):
|
|||||||
|
|
||||||
self.failed_folders = []
|
self.failed_folders = []
|
||||||
|
|
||||||
def dbpath(self, id):
|
def dbpath(self, id_):
|
||||||
return self.db.path(id, index_is_id=True)
|
return self.db.path(id_, index_is_id=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def errors_occurred(self):
|
def errors_occurred(self):
|
||||||
@ -116,21 +116,21 @@ class CheckLibrary(object):
|
|||||||
self.invalid_titles.append((auth_dir, db_path, 0))
|
self.invalid_titles.append((auth_dir, db_path, 0))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
id = m.group(1)
|
id_ = m.group(1)
|
||||||
# Third check: the id must be in the DB and the paths must match
|
# Third check: the id_ must be in the DB and the paths must match
|
||||||
if self.is_case_sensitive:
|
if self.is_case_sensitive:
|
||||||
if int(id) not in self.all_ids or \
|
if int(id_) not in self.all_ids or \
|
||||||
db_path not in self.all_dbpaths:
|
db_path not in self.all_dbpaths:
|
||||||
self.extra_titles.append((title_dir, db_path, 0))
|
self.extra_titles.append((title_dir, db_path, 0))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
if int(id) not in self.all_ids or \
|
if int(id_) not in self.all_ids or \
|
||||||
db_path.lower() not in self.all_lc_dbpaths:
|
db_path.lower() not in self.all_lc_dbpaths:
|
||||||
self.extra_titles.append((title_dir, db_path, 0))
|
self.extra_titles.append((title_dir, db_path, 0))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Record the book to check its formats
|
# Record the book to check its formats
|
||||||
self.book_dirs.append((db_path, title_dir, id))
|
self.book_dirs.append((db_path, title_dir, id_))
|
||||||
found_titles = True
|
found_titles = True
|
||||||
|
|
||||||
# Fourth check: author directories that contain no titles
|
# Fourth check: author directories that contain no titles
|
||||||
@ -145,6 +145,21 @@ class CheckLibrary(object):
|
|||||||
# Sort-of check: exception processing directory
|
# Sort-of check: exception processing directory
|
||||||
self.failed_folders.append((title_path, traceback.format_exc(), []))
|
self.failed_folders.append((title_path, traceback.format_exc(), []))
|
||||||
|
|
||||||
|
# Check for formats and covers in db for book dirs that are gone
|
||||||
|
for id_ in self.all_ids:
|
||||||
|
path = self.dbpath(id_)
|
||||||
|
if not os.path.exists(os.path.join(lib, path)):
|
||||||
|
title_dir = os.path.basename(path)
|
||||||
|
book_formats = frozenset([x for x in
|
||||||
|
self.db.format_files(id_, index_is_id=True)])
|
||||||
|
for fmt in book_formats:
|
||||||
|
self.missing_formats.append((title_dir,
|
||||||
|
os.path.join(path, fmt[0]+'.'+fmt[1].lower()), id_))
|
||||||
|
if self.db.has_cover(id_):
|
||||||
|
self.missing_covers.append((title_dir,
|
||||||
|
os.path.join(path, 'cover.jpg'), id_))
|
||||||
|
|
||||||
|
|
||||||
def is_ebook_file(self, filename):
|
def is_ebook_file(self, filename):
|
||||||
ext = os.path.splitext(filename)[1]
|
ext = os.path.splitext(filename)[1]
|
||||||
if not ext:
|
if not ext:
|
||||||
@ -226,8 +241,8 @@ class CheckLibrary(object):
|
|||||||
if self.db.has_cover(book_id):
|
if self.db.has_cover(book_id):
|
||||||
if 'cover.jpg' not in filenames:
|
if 'cover.jpg' not in filenames:
|
||||||
self.missing_covers.append((title_dir,
|
self.missing_covers.append((title_dir,
|
||||||
os.path.join(db_path, title_dir, 'cover.jpg'), book_id))
|
os.path.join(db_path, 'cover.jpg'), book_id))
|
||||||
else:
|
else:
|
||||||
if 'cover.jpg' in filenames:
|
if 'cover.jpg' in filenames:
|
||||||
self.extra_covers.append((title_dir,
|
self.extra_covers.append((title_dir,
|
||||||
os.path.join(db_path, title_dir, 'cover.jpg'), book_id))
|
os.path.join(db_path, 'cover.jpg'), book_id))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user