From 5742f5b9dc19a735779945af501cb2f10ce5394d Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 1 Oct 2010 17:10:26 +0100 Subject: [PATCH] Added a tweak to ignore certain names and extensions in check_library.py --- resources/default_tweaks.py | 8 ++++++++ src/calibre/library/check_library.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 095eba0c3d..af2b27b717 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -171,3 +171,11 @@ content_server_wont_display = [''] # level sorts, and if you are seeing a slowdown, reduce the value of this tweak. maximum_resort_levels = 5 + +# Select names and extensions that check library will not report. +# Example: to ignore all jpgs and pngs +# check_library_ignore_extensions=['jpg', 'png'] +# Example: to ignore all instances of _catalog (calibre2opds) and its children: +# check_library_ignore_names=['_catalog'] +check_library_ignore_names=[] +check_library_ignore_extensions=[] diff --git a/src/calibre/library/check_library.py b/src/calibre/library/check_library.py index f78912544b..22ec60160f 100644 --- a/src/calibre/library/check_library.py +++ b/src/calibre/library/check_library.py @@ -10,6 +10,7 @@ import re, os, traceback from calibre import isbytestring from calibre.constants import filesystem_encoding from calibre.ebooks import BOOK_EXTENSIONS +from calibre.utils.config import tweaks EBOOK_EXTENSIONS = frozenset(BOOK_EXTENSIONS) @@ -36,6 +37,10 @@ class CheckLibrary(object): self.is_case_sensitive = db.is_case_sensitive + self.ignore_names = frozenset(tweaks['check_library_ignore_names']) + self.ignore_ext = frozenset(['.'+ e for e in + tweaks['check_library_ignore_extensions']]) + 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) @@ -71,6 +76,8 @@ class CheckLibrary(object): def scan_library(self): lib = self.src_library_path for auth_dir in os.listdir(lib): + if auth_dir in self.ignore_names: + continue auth_path = os.path.join(lib, auth_dir) # First check: author must be a directory if not os.path.isdir(auth_path): @@ -82,6 +89,8 @@ class CheckLibrary(object): # Look for titles in the author directories found_titles = False for title_dir in os.listdir(auth_path): + if title_dir in self.ignore_names: + continue title_path = os.path.join(auth_path, title_dir) db_path = os.path.join(auth_dir, title_dir) m = self.db_id_regexp.search(title_dir) @@ -131,7 +140,8 @@ class CheckLibrary(object): def process_book(self, lib, book_info): (db_path, title_dir, book_id) = book_info - filenames = frozenset(os.listdir(os.path.join(lib, db_path))) + filenames = frozenset([f for f in os.listdir(os.path.join(lib, db_path)) + if os.path.splitext(f)[1] not in self.ignore_ext]) book_id = int(book_id) formats = frozenset(filter(self.is_ebook_file, filenames)) book_formats = frozenset([x[0]+'.'+x[1].lower() for x in