From 2959f44e24224afaefcb088ba25d072a96b2f438 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 14 Feb 2016 14:02:07 +0530 Subject: [PATCH] fix add missing --- oml/item/scan.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/oml/item/scan.py b/oml/item/scan.py index 72e2dd9..390ad81 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -30,8 +30,7 @@ def remove_missing(books=None): if books is None: books = collect_books() with db.session(): - prefs = settings.preferences - prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep) + prefix = get_prefix() if os.path.exists(prefix): logger.debug('scan for removed files') db_paths = [] @@ -90,14 +89,18 @@ def add_file(id, f, prefix, from_=None, commit=True): logger.debug('%s added', id) return file -def collect_books(): +def get_prefix(): prefs = settings.preferences prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep) if not prefix[-1] == os.sep: prefix += os.sep assert isinstance(prefix, str) + return prefix + +def collect_books(): logger.debug('collect books') books = [] + prefix = get_prefix() for root, folders, files in os.walk(prefix): for f in files: if state.shutdown: @@ -115,6 +118,7 @@ def collect_books(): def run_scan(): logger.debug('run_scan') + prefix = get_prefix() books = collect_books() remove_missing(books) @@ -159,7 +163,7 @@ def run_import(options=None): prefix = os.path.realpath(prefix) if not prefix[-1] == os.sep: prefix += os.sep - prefix_books = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep) + prefix_books = get_prefix() prefix_imported = os.path.join(prefix_books, '.import' + os.sep) if prefix_books.startswith(prefix) or prefix.startswith(prefix_books): error = 'invalid path'