mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
9f27932af9
@ -3,8 +3,9 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
|
|
||||||
from PyQt4.Qt import QDialog, QVBoxLayout, QTreeWidget, QPushButton, \
|
from PyQt4.Qt import QDialog, QVBoxLayout, QHBoxLayout, QTreeWidget, QLabel, \
|
||||||
QDialogButtonBox, QApplication, QTreeWidgetItem
|
QPushButton, QDialogButtonBox, QApplication, QTreeWidgetItem, \
|
||||||
|
QLineEdit
|
||||||
|
|
||||||
from calibre.library.check_library import CheckLibrary, CHECKS
|
from calibre.library.check_library import CheckLibrary, CHECKS
|
||||||
|
|
||||||
@ -17,11 +18,13 @@ class CheckLibraryDialog(QDialog):
|
|||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
self.db = db
|
self.db = db
|
||||||
|
|
||||||
|
self.setWindowTitle(_('Check Library'))
|
||||||
|
|
||||||
self._layout = QVBoxLayout(self)
|
self._layout = QVBoxLayout(self)
|
||||||
self.setLayout(self._layout)
|
self.setLayout(self._layout)
|
||||||
|
|
||||||
self.log = QTreeWidget(self)
|
self.log = QTreeWidget(self)
|
||||||
self._layout.addWidget(self.log)
|
self._layout.addWidget(self.log)
|
||||||
self.setWindowTitle(_('Check Library'))
|
|
||||||
|
|
||||||
self.check = QPushButton(_('Run the check'))
|
self.check = QPushButton(_('Run the check'))
|
||||||
self.check.setDefault(False)
|
self.check.setDefault(False)
|
||||||
@ -32,20 +35,50 @@ class CheckLibraryDialog(QDialog):
|
|||||||
self.ok = QPushButton('&OK')
|
self.ok = QPushButton('&OK')
|
||||||
self.ok.setDefault(True)
|
self.ok.setDefault(True)
|
||||||
self.ok.clicked.connect(self.accept)
|
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 = QDialogButtonBox(self)
|
||||||
self.bbox.addButton(self.copy, QDialogButtonBox.ActionRole)
|
self.bbox.addButton(self.copy, QDialogButtonBox.ActionRole)
|
||||||
self.bbox.addButton(self.check, QDialogButtonBox.ActionRole)
|
self.bbox.addButton(self.check, QDialogButtonBox.ActionRole)
|
||||||
|
self.bbox.addButton(self.cancel, QDialogButtonBox.RejectRole)
|
||||||
self.bbox.addButton(self.ok, QDialogButtonBox.AcceptRole)
|
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._layout.addWidget(self.bbox)
|
||||||
self.resize(750, 500)
|
self.resize(750, 500)
|
||||||
self.bbox.setEnabled(True)
|
self.bbox.setEnabled(True)
|
||||||
|
|
||||||
self.run_the_check()
|
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):
|
def run_the_check(self):
|
||||||
checker = CheckLibrary(self.db.library_path, self.db)
|
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.ext_ignores.text())))
|
||||||
|
|
||||||
plaintext = []
|
plaintext = []
|
||||||
|
|
||||||
|
@ -68,9 +68,14 @@ class CheckLibrary(object):
|
|||||||
return self.failed_folders or self.mismatched_dirs or \
|
return self.failed_folders or self.mismatched_dirs or \
|
||||||
self.conflicting_custom_cols or self.failed_restores
|
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
|
lib = self.src_library_path
|
||||||
for auth_dir in os.listdir(lib):
|
for auth_dir in os.listdir(lib):
|
||||||
|
if auth_dir in self.ignore_names:
|
||||||
|
continue
|
||||||
auth_path = os.path.join(lib, auth_dir)
|
auth_path = os.path.join(lib, auth_dir)
|
||||||
# First check: author must be a directory
|
# First check: author must be a directory
|
||||||
if not os.path.isdir(auth_path):
|
if not os.path.isdir(auth_path):
|
||||||
@ -82,6 +87,8 @@ class CheckLibrary(object):
|
|||||||
# Look for titles in the author directories
|
# Look for titles in the author directories
|
||||||
found_titles = False
|
found_titles = False
|
||||||
for title_dir in os.listdir(auth_path):
|
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)
|
title_path = os.path.join(auth_path, title_dir)
|
||||||
db_path = os.path.join(auth_dir, title_dir)
|
db_path = os.path.join(auth_dir, title_dir)
|
||||||
m = self.db_id_regexp.search(title_dir)
|
m = self.db_id_regexp.search(title_dir)
|
||||||
@ -131,7 +138,8 @@ class CheckLibrary(object):
|
|||||||
|
|
||||||
def process_book(self, lib, book_info):
|
def process_book(self, lib, book_info):
|
||||||
(db_path, title_dir, book_id) = 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)
|
book_id = int(book_id)
|
||||||
formats = frozenset(filter(self.is_ebook_file, filenames))
|
formats = frozenset(filter(self.is_ebook_file, filenames))
|
||||||
book_formats = frozenset([x[0]+'.'+x[1].lower() for x in
|
book_formats = frozenset([x[0]+'.'+x[1].lower() for x in
|
||||||
|
@ -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',
|
parser.add_option('-r', '--report', default=None, dest='report',
|
||||||
help=_("Comma-separated list of reports.\n"
|
help=_("Comma-separated list of reports.\n"
|
||||||
"Default: all"))
|
"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
|
return parser
|
||||||
|
|
||||||
def command_check_library(args, dbpath):
|
def command_check_library(args, dbpath):
|
||||||
@ -919,6 +927,15 @@ def command_check_library(args, dbpath):
|
|||||||
print _('Unknown report check'), r
|
print _('Unknown report check'), r
|
||||||
return 1
|
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):
|
def print_one(checker, check):
|
||||||
attr = check[0]
|
attr = check[0]
|
||||||
list = getattr(checker, attr, None)
|
list = getattr(checker, attr, None)
|
||||||
@ -934,7 +951,7 @@ def command_check_library(args, dbpath):
|
|||||||
|
|
||||||
db = LibraryDatabase2(dbpath)
|
db = LibraryDatabase2(dbpath)
|
||||||
checker = CheckLibrary(dbpath, db)
|
checker = CheckLibrary(dbpath, db)
|
||||||
checker.scan_library()
|
checker.scan_library(names, exts)
|
||||||
for check in checks:
|
for check in checks:
|
||||||
print_one(checker, check)
|
print_one(checker, check)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user