fix add missing
This commit is contained in:
parent
0689563c4d
commit
2959f44e24
1 changed files with 8 additions and 4 deletions
|
@ -30,8 +30,7 @@ def remove_missing(books=None):
|
||||||
if books is None:
|
if books is None:
|
||||||
books = collect_books()
|
books = collect_books()
|
||||||
with db.session():
|
with db.session():
|
||||||
prefs = settings.preferences
|
prefix = get_prefix()
|
||||||
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep)
|
|
||||||
if os.path.exists(prefix):
|
if os.path.exists(prefix):
|
||||||
logger.debug('scan for removed files')
|
logger.debug('scan for removed files')
|
||||||
db_paths = []
|
db_paths = []
|
||||||
|
@ -90,14 +89,18 @@ def add_file(id, f, prefix, from_=None, commit=True):
|
||||||
logger.debug('%s added', id)
|
logger.debug('%s added', id)
|
||||||
return file
|
return file
|
||||||
|
|
||||||
def collect_books():
|
def get_prefix():
|
||||||
prefs = settings.preferences
|
prefs = settings.preferences
|
||||||
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep)
|
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books' + os.sep)
|
||||||
if not prefix[-1] == os.sep:
|
if not prefix[-1] == os.sep:
|
||||||
prefix += os.sep
|
prefix += os.sep
|
||||||
assert isinstance(prefix, str)
|
assert isinstance(prefix, str)
|
||||||
|
return prefix
|
||||||
|
|
||||||
|
def collect_books():
|
||||||
logger.debug('collect books')
|
logger.debug('collect books')
|
||||||
books = []
|
books = []
|
||||||
|
prefix = get_prefix()
|
||||||
for root, folders, files in os.walk(prefix):
|
for root, folders, files in os.walk(prefix):
|
||||||
for f in files:
|
for f in files:
|
||||||
if state.shutdown:
|
if state.shutdown:
|
||||||
|
@ -115,6 +118,7 @@ def collect_books():
|
||||||
|
|
||||||
def run_scan():
|
def run_scan():
|
||||||
logger.debug('run_scan')
|
logger.debug('run_scan')
|
||||||
|
prefix = get_prefix()
|
||||||
books = collect_books()
|
books = collect_books()
|
||||||
remove_missing(books)
|
remove_missing(books)
|
||||||
|
|
||||||
|
@ -159,7 +163,7 @@ def run_import(options=None):
|
||||||
prefix = os.path.realpath(prefix)
|
prefix = os.path.realpath(prefix)
|
||||||
if not prefix[-1] == os.sep:
|
if not prefix[-1] == os.sep:
|
||||||
prefix += 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)
|
prefix_imported = os.path.join(prefix_books, '.import' + os.sep)
|
||||||
if prefix_books.startswith(prefix) or prefix.startswith(prefix_books):
|
if prefix_books.startswith(prefix) or prefix.startswith(prefix_books):
|
||||||
error = 'invalid path'
|
error = 'invalid path'
|
||||||
|
|
Loading…
Reference in a new issue