mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More case-sensitive work
This commit is contained in:
parent
2665524310
commit
fc2dcd2020
@ -34,12 +34,12 @@ class CheckLibrary(object):
|
||||
self.src_library_path = os.path.abspath(library_path)
|
||||
self.db = db
|
||||
|
||||
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.is_case_sensitive = db.is_case_sensitive
|
||||
self.all_dbpaths = frozenset(self.dbpath(id) for id in self.all_ids)
|
||||
self.all_lc_dbpaths = frozenset(self.dbpath(id).lower()
|
||||
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+)\)$')
|
||||
self.bad_ext_pat = re.compile(r'[^a-z]+')
|
||||
@ -132,35 +132,50 @@ 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_lc = frozenset(f.lower() for f in filenames)
|
||||
book_id = int(book_id)
|
||||
formats = frozenset(filter(self.is_ebook_file, filenames))
|
||||
formats_lc = frozenset(f.lower() for f in formats)
|
||||
|
||||
# Check: any books that aren't formats or normally there?
|
||||
if self.is_case_sensitive:
|
||||
unknowns = frozenset(filenames-formats-NORMALS)
|
||||
else:
|
||||
unknowns = frozenset(filenames_lc-formats_lc-NORMALS)
|
||||
if unknowns:
|
||||
self.extra_files.append((title_dir, db_path, unknowns))
|
||||
|
||||
book_formats = frozenset([x[0]+'.'+x[1].lower() for x in
|
||||
self.db.format_files(book_id, index_is_id=True)])
|
||||
book_formats_lc = frozenset(f.lower() for f in book_formats)
|
||||
|
||||
# Check: any book formats that should be there?
|
||||
if self.is_case_sensitive:
|
||||
unknowns = frozenset(filenames-formats-NORMALS)
|
||||
# Check: any books that aren't formats or normally there?
|
||||
if unknowns:
|
||||
self.extra_files.append((title_dir, db_path, unknowns))
|
||||
|
||||
# Check: any book formats that should be there?
|
||||
missing = book_formats - formats
|
||||
else:
|
||||
missing = book_formats_lc - formats_lc
|
||||
if missing:
|
||||
self.missing_formats.append((title_dir, db_path, missing))
|
||||
if missing:
|
||||
self.missing_formats.append((title_dir, db_path, missing))
|
||||
|
||||
# Check: any book formats that shouldn't be there?
|
||||
if self.is_case_sensitive:
|
||||
# Check: any book formats that shouldn't be there?
|
||||
extra = formats - book_formats
|
||||
if extra:
|
||||
self.extra_formats.append((title_dir, db_path, extra))
|
||||
else:
|
||||
def lc_map(fnames, fset):
|
||||
m = {}
|
||||
for f in fnames:
|
||||
m[f.lower()] = f
|
||||
return [m[f] for f in fset]
|
||||
|
||||
filenames_lc = frozenset([f.lower() for f in filenames])
|
||||
formats_lc = frozenset([f.lower() for f in formats])
|
||||
unknowns = frozenset(filenames_lc-formats_lc-NORMALS)
|
||||
# Check: any books that aren't formats or normally there?
|
||||
if unknowns:
|
||||
self.extra_files.append((title_dir, db_path,
|
||||
lc_map(filenames, unknowns)))
|
||||
|
||||
book_formats_lc = frozenset([f.lower() for f in book_formats])
|
||||
# Check: any book formats that should be there?
|
||||
missing = book_formats_lc - formats_lc
|
||||
if missing:
|
||||
self.missing_formats.append((title_dir, db_path,
|
||||
lc_map(book_formats, missing)))
|
||||
|
||||
# Check: any book formats that shouldn't be there?
|
||||
extra = formats_lc - book_formats_lc
|
||||
if extra:
|
||||
self.extra_formats.append((title_dir, db_path, extra))
|
||||
if extra:
|
||||
self.extra_formats.append((title_dir, db_path,
|
||||
lc_map(formats, extra)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user