From d41112fad791c27ecbd22e0e09e7625fb631744b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 24 Mar 2012 10:52:23 +0100 Subject: [PATCH 1/2] Fix doc string for series_sort formatter function. --- src/calibre/utils/formatter_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index f7b5ea7bca..bfb2f036c0 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -841,7 +841,7 @@ class BuiltinSeriesSort(BuiltinFormatterFunction): name = 'series_sort' arg_count = 0 category = 'Get values from metadata' - __doc__ = doc = _('booksize() -- return the series sort value') + __doc__ = doc = _('series_sort() -- return the series sort value') def evaluate(self, formatter, kwargs, mi, locals): if mi.series: From ce26007ad3d806a5f31ac21b9bc7fdf4e8178bf4 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 24 Mar 2012 11:46:15 +0100 Subject: [PATCH 2/2] 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. --- src/calibre/library/check_library.py | 37 +++++++++++++++++++--------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/calibre/library/check_library.py b/src/calibre/library/check_library.py index 486913e0c9..924fedf7ed 100644 --- a/src/calibre/library/check_library.py +++ b/src/calibre/library/check_library.py @@ -47,8 +47,8 @@ class CheckLibrary(object): self.is_case_sensitive = db.is_case_sensitive 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_dbpaths = frozenset(self.dbpath(id) for id in self.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_lc_dbpaths = frozenset([f.lower() for f in self.all_dbpaths]) self.db_id_regexp = re.compile(r'^.* \((\d+)\)$') @@ -73,8 +73,8 @@ class CheckLibrary(object): self.failed_folders = [] - def dbpath(self, id): - return self.db.path(id, index_is_id=True) + def dbpath(self, id_): + return self.db.path(id_, index_is_id=True) @property def errors_occurred(self): @@ -116,21 +116,21 @@ class CheckLibrary(object): self.invalid_titles.append((auth_dir, db_path, 0)) continue - id = m.group(1) - # Third check: the id must be in the DB and the paths must match + id_ = m.group(1) + # Third check: the id_ must be in the DB and the paths must match 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: self.extra_titles.append((title_dir, db_path, 0)) continue 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: self.extra_titles.append((title_dir, db_path, 0)) continue # 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 # Fourth check: author directories that contain no titles @@ -145,6 +145,21 @@ class CheckLibrary(object): # Sort-of check: exception processing directory 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): ext = os.path.splitext(filename)[1] if not ext: @@ -226,8 +241,8 @@ class CheckLibrary(object): if self.db.has_cover(book_id): if 'cover.jpg' not in filenames: 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: if 'cover.jpg' in filenames: 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))