diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index af2b27b717..095eba0c3d 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -171,11 +171,3 @@ 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/gui2/dialogs/check_library.py b/src/calibre/gui2/dialogs/check_library.py index 177e12db49..c61b1f8c90 100644 --- a/src/calibre/gui2/dialogs/check_library.py +++ b/src/calibre/gui2/dialogs/check_library.py @@ -3,8 +3,9 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' __license__ = 'GPL v3' -from PyQt4.Qt import QDialog, QVBoxLayout, QTreeWidget, QPushButton, \ - QDialogButtonBox, QApplication, QTreeWidgetItem +from PyQt4.Qt import QDialog, QVBoxLayout, QHBoxLayout, QTreeWidget, QLabel, \ + QPushButton, QDialogButtonBox, QApplication, QTreeWidgetItem, \ + QLineEdit from calibre.library.check_library import CheckLibrary, CHECKS @@ -17,11 +18,13 @@ class CheckLibraryDialog(QDialog): QDialog.__init__(self, parent) self.db = db + self.setWindowTitle(_('Check Library')) + self._layout = QVBoxLayout(self) self.setLayout(self._layout) + self.log = QTreeWidget(self) self._layout.addWidget(self.log) - self.setWindowTitle(_('Check Library')) self.check = QPushButton(_('Run the check')) self.check.setDefault(False) @@ -32,20 +35,50 @@ class CheckLibraryDialog(QDialog): self.ok = QPushButton('&OK') self.ok.setDefault(True) self.ok.clicked.connect(self.accept) + self.cancel = QPushButton('&Cancel') + self.cancel.setDefault(False) + self.cancel.clicked.connect(self.reject) self.bbox = QDialogButtonBox(self) self.bbox.addButton(self.copy, QDialogButtonBox.ActionRole) self.bbox.addButton(self.check, QDialogButtonBox.ActionRole) + self.bbox.addButton(self.cancel, QDialogButtonBox.RejectRole) self.bbox.addButton(self.ok, QDialogButtonBox.AcceptRole) + h = QHBoxLayout() + ln = QLabel(_('Names to ignore:')) + h.addWidget(ln) + self.name_ignores = QLineEdit() + self.name_ignores.setText(db.prefs.get('check_library_ignore_names', '')) + ln.setBuddy(self.name_ignores) + h.addWidget(self.name_ignores) + le = QLabel(_('Extensions to ignore')) + h.addWidget(le) + self.ext_ignores = QLineEdit() + self.ext_ignores.setText(db.prefs.get('check_library_ignore_extensions', '')) + le.setBuddy(self.ext_ignores) + h.addWidget(self.ext_ignores) + self._layout.addLayout(h) + self._layout.addWidget(self.bbox) self.resize(750, 500) self.bbox.setEnabled(True) self.run_the_check() + def accept(self): + self.db.prefs['check_library_ignore_extensions'] = \ + unicode(self.ext_ignores.text()) + self.db.prefs['check_library_ignore_names'] = \ + unicode(self.name_ignores.text()) + QDialog.accept(self) + + def box_to_list(self, txt): + return [f.strip().lower() for f in txt.split(',') if f.strip()] + def run_the_check(self): checker = CheckLibrary(self.db.library_path, self.db) - checker.scan_library() + checker.scan_library(self.box_to_list(unicode(self.name_ignores.text())), + self.box_to_list(unicode(self.name_ignores.text()))) plaintext = [] diff --git a/src/calibre/library/check_library.py b/src/calibre/library/check_library.py index 22ec60160f..7271491f47 100644 --- a/src/calibre/library/check_library.py +++ b/src/calibre/library/check_library.py @@ -10,7 +10,6 @@ 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) @@ -37,10 +36,6 @@ 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) @@ -73,7 +68,10 @@ class CheckLibrary(object): return self.failed_folders or self.mismatched_dirs or \ self.conflicting_custom_cols or self.failed_restores - def scan_library(self): + def scan_library(self, name_ignores, extension_ignores): + self.ignore_names = frozenset(name_ignores) + self.ignore_ext = frozenset(['.'+ e for e in extension_ignores]) + lib = self.src_library_path for auth_dir in os.listdir(lib): if auth_dir in self.ignore_names: diff --git a/src/calibre/library/cli.py b/src/calibre/library/cli.py index d504e670e0..5b12692764 100644 --- a/src/calibre/library/cli.py +++ b/src/calibre/library/cli.py @@ -888,6 +888,14 @@ Perform some checks on the filesystem representing a library. Reports are {0} parser.add_option('-r', '--report', default=None, dest='report', help=_("Comma-separated list of reports.\n" "Default: all")) + + parser.add_option('-e', '--ignore_extensions', default=None, dest='exts', + help=_("Comma-separated list of extensions to ignore.\n" + "Default: all")) + + parser.add_option('-n', '--ignore_names', default=None, dest='names', + help=_("Comma-separated list of names to ignore.\n" + "Default: all")) return parser def command_check_library(args, dbpath): @@ -919,6 +927,15 @@ def command_check_library(args, dbpath): print _('Unknown report check'), r return 1 + if opts.names is None: + names = [] + else: + names = [f.strip().lower() for f in opts.names.split(',') if f.strip()] + if opts.exts is None: + exts = [] + else: + exts = [f.strip().lower() for f in opts.exts.split(',') if f.strip()] + def print_one(checker, check): attr = check[0] list = getattr(checker, attr, None) @@ -934,7 +951,7 @@ def command_check_library(args, dbpath): db = LibraryDatabase2(dbpath) checker = CheckLibrary(dbpath, db) - checker.scan_library() + checker.scan_library(names, exts) for check in checks: print_one(checker, check)