Change check_library.py to not report non-book formats as both extra and missing.

This commit is contained in:
Charles Haley 2011-09-18 09:30:19 +02:00
parent fe976eff7a
commit 257db2ffad

View File

@ -167,16 +167,20 @@ class CheckLibrary(object):
if self.is_case_sensitive: if self.is_case_sensitive:
unknowns = frozenset(filenames-formats-NORMALS) unknowns = frozenset(filenames-formats-NORMALS)
missing = book_formats - formats
# Check: any books that aren't formats or normally there? # Check: any books that aren't formats or normally there?
for u in unknowns: for fn in unknowns:
if fn in missing: # An unknown format correctly registered
continue
self.extra_files.append((title_dir, self.extra_files.append((title_dir,
os.path.join(db_path, u), book_id)) os.path.join(db_path, fn), book_id))
# Check: any book formats that should be there? # Check: any book formats that should be there?
missing = book_formats - formats for fn in missing:
for m in missing: if fn in unknowns: # An unknown format correctly registered
continue
self.missing_formats.append((title_dir, self.missing_formats.append((title_dir,
os.path.join(db_path, m), book_id)) os.path.join(db_path, fn), book_id))
# Check: any book formats that shouldn't be there? # Check: any book formats that shouldn't be there?
extra = formats - book_formats - NORMALS extra = formats - book_formats - NORMALS
@ -185,25 +189,32 @@ class CheckLibrary(object):
os.path.join(db_path, e), book_id)) os.path.join(db_path, e), book_id))
else: else:
def lc_map(fnames, fset): def lc_map(fnames, fset):
m = {} fn = {}
for f in fnames: for f in fnames:
m[f.lower()] = f ff = f.lower()
return [m[f] for f in fset] if ff in fset:
fn[ff] = f
return fn
filenames_lc = frozenset([f.lower() for f in filenames]) filenames_lc = frozenset([f.lower() for f in filenames])
formats_lc = frozenset([f.lower() for f in formats]) formats_lc = frozenset([f.lower() for f in formats])
unknowns = frozenset(filenames_lc-formats_lc-NORMALS) unknowns = frozenset(filenames_lc-formats_lc-NORMALS)
book_formats_lc = frozenset([f.lower() for f in book_formats])
missing = book_formats_lc - formats_lc
# Check: any books that aren't formats or normally there? # Check: any books that aren't formats or normally there?
for f in lc_map(filenames, unknowns): for lcfn,ccfn in lc_map(filenames, unknowns).iteritems():
self.extra_files.append((title_dir, os.path.join(db_path, f), if lcfn in missing: # An unknown format correctly registered
continue
self.extra_files.append((title_dir, os.path.join(db_path, ccfn),
book_id)) book_id))
book_formats_lc = frozenset([f.lower() for f in book_formats])
# Check: any book formats that should be there? # Check: any book formats that should be there?
missing = book_formats_lc - formats_lc for lcfn,ccfn in lc_map(book_formats, missing).iteritems():
for m in lc_map(book_formats, missing): if lcfn in unknowns: # An unknown format correctly registered
continue
self.missing_formats.append((title_dir, self.missing_formats.append((title_dir,
os.path.join(db_path, m), book_id)) os.path.join(db_path, ccfn), book_id))
# Check: any book formats that shouldn't be there? # Check: any book formats that shouldn't be there?
extra = formats_lc - book_formats_lc - NORMALS extra = formats_lc - book_formats_lc - NORMALS