attempt to cleanup library
This commit is contained in:
parent
7a000bf199
commit
56df24baad
1 changed files with 26 additions and 0 deletions
|
@ -132,6 +132,7 @@ def run_scan():
|
|||
prefix = get_prefix()
|
||||
books = collect_books(prefix)
|
||||
remove_missing(books)
|
||||
ids = set()
|
||||
|
||||
added = 0
|
||||
|
||||
|
@ -143,6 +144,16 @@ def run_scan():
|
|||
if os.path.exists(f):
|
||||
id = media.get_id(f)
|
||||
file = File.get(id)
|
||||
if id in ids:
|
||||
logger.debug('file exists in multiple locations %s', id)
|
||||
if file:
|
||||
f1 = file.fullpath()
|
||||
f2 = os.path.join(prefix, f)
|
||||
if f1 != f2 and os.path.exists(f1) and os.path.exists(f2):
|
||||
logger.debug('"%s" vs "%s"', f1, f2)
|
||||
else:
|
||||
ids.add(id)
|
||||
|
||||
if not file:
|
||||
file = add_file(id, f, prefix, f)
|
||||
added += 1
|
||||
|
@ -154,9 +165,24 @@ def run_scan():
|
|||
add_record('edititem', item.id, item.meta)
|
||||
item.update()
|
||||
added += 1
|
||||
library_items = len(user.library.items)
|
||||
if added:
|
||||
trigger_event('change', {})
|
||||
logger.debug('imported %s unknown books', added)
|
||||
if len(ids) != len(books):
|
||||
logger.debug('number of books %s vs number of ids %s', len(books), len(ids))
|
||||
if library_items != len(books):
|
||||
logger.debug('number of books %s vs number of items in library %s', len(books), library_items)
|
||||
library_items = set([str(i) for i in user.library.items])
|
||||
gone = library_items - ids
|
||||
if gone:
|
||||
logger.debug('cleaning up %s deleted records', len(gone))
|
||||
for id in gone:
|
||||
i = Item.get(id)
|
||||
i.remove_file()
|
||||
missing = ids - library_items
|
||||
if missing:
|
||||
logger.debug('%s items in library without a record', len(missing))
|
||||
|
||||
def change_path(old, new):
|
||||
new_books = os.path.join(new, 'Books')
|
||||
|
|
Loading…
Reference in a new issue