trigger fs scan after changing path, move folder if new path does not exist, fixes #214
This commit is contained in:
parent
2e04379838
commit
e27e429fd6
3 changed files with 25 additions and 4 deletions
|
@ -43,6 +43,7 @@ def remove_missing():
|
||||||
dirty = True
|
dirty = True
|
||||||
if dirty:
|
if dirty:
|
||||||
state.db.session.commit()
|
state.db.session.commit()
|
||||||
|
state.cache.clear('group:')
|
||||||
for f in File.query:
|
for f in File.query:
|
||||||
if not state.tasks.connected:
|
if not state.tasks.connected:
|
||||||
return
|
return
|
||||||
|
@ -107,6 +108,17 @@ def run_scan():
|
||||||
added += 1
|
added += 1
|
||||||
trigger_event('change', {})
|
trigger_event('change', {})
|
||||||
|
|
||||||
|
def change_path(old, new):
|
||||||
|
new_books = os.path.join(new, 'Books')
|
||||||
|
if not os.path.exists(new_books):
|
||||||
|
ox.makedirs(new)
|
||||||
|
shutil.move(os.path.join(old, 'Books'), new_books)
|
||||||
|
remove_empty_folders(old)
|
||||||
|
else:
|
||||||
|
ox.makedirs(new_books)
|
||||||
|
run_scan()
|
||||||
|
trigger_event('change', {})
|
||||||
|
|
||||||
def run_import(options=None):
|
def run_import(options=None):
|
||||||
options = options or {}
|
options = options or {}
|
||||||
logger.debug('run_import')
|
logger.debug('run_import')
|
||||||
|
|
|
@ -29,7 +29,9 @@ class Tasks(Thread):
|
||||||
try:
|
try:
|
||||||
action, data = m
|
action, data = m
|
||||||
logger.debug('%s start', action)
|
logger.debug('%s start', action)
|
||||||
if action == 'export':
|
if action == 'changelibrarypath':
|
||||||
|
item.scan.change_path(data[0], data[1])
|
||||||
|
elif action == 'export':
|
||||||
export_list(data)
|
export_list(data)
|
||||||
elif action == 'getpreview':
|
elif action == 'getpreview':
|
||||||
get_preview(data)
|
get_preview(data)
|
||||||
|
|
|
@ -66,6 +66,11 @@ def setPreferences(data):
|
||||||
data['contact'] != settings.preferences['contact']
|
data['contact'] != settings.preferences['contact']
|
||||||
change_username = 'username' in data and \
|
change_username = 'username' in data and \
|
||||||
data['username'] != settings.preferences['username']
|
data['username'] != settings.preferences['username']
|
||||||
|
if 'libraryPath' in data and \
|
||||||
|
data['libraryPath'] != settings.preferences['libraryPath']:
|
||||||
|
change_path = [settings.preferences['libraryPath'], data['libraryPath']]
|
||||||
|
else:
|
||||||
|
change_path = False
|
||||||
update_dict(settings.preferences, data)
|
update_dict(settings.preferences, data)
|
||||||
if 'username' in data:
|
if 'username' in data:
|
||||||
u = state.user()
|
u = state.user()
|
||||||
|
@ -75,8 +80,10 @@ def setPreferences(data):
|
||||||
Changelog.record(u, 'editusername', data['username'])
|
Changelog.record(u, 'editusername', data['username'])
|
||||||
if change_contact:
|
if change_contact:
|
||||||
Changelog.record(state.user(), 'editcontact', data['contact'])
|
Changelog.record(state.user(), 'editcontact', data['contact'])
|
||||||
|
if change_path:
|
||||||
|
state.tasks.queue('changelibrarypath', change_path)
|
||||||
return settings.preferences
|
return settings.preferences
|
||||||
actions.register(setPreferences)
|
actions.register(setPreferences, cache=False)
|
||||||
|
|
||||||
def resetUI(data):
|
def resetUI(data):
|
||||||
'''
|
'''
|
||||||
|
@ -88,7 +95,7 @@ def resetUI(data):
|
||||||
os.unlink(ui_json)
|
os.unlink(ui_json)
|
||||||
settings.ui = settings.pdict(ui_json, settings.config['user']['ui'])
|
settings.ui = settings.pdict(ui_json, settings.config['user']['ui'])
|
||||||
return settings.ui
|
return settings.ui
|
||||||
actions.register(resetUI)
|
actions.register(resetUI, cache=False)
|
||||||
|
|
||||||
def setUI(data):
|
def setUI(data):
|
||||||
'''
|
'''
|
||||||
|
@ -99,7 +106,7 @@ def setUI(data):
|
||||||
'''
|
'''
|
||||||
update_dict(settings.ui, data)
|
update_dict(settings.ui, data)
|
||||||
return settings.ui
|
return settings.ui
|
||||||
actions.register(setUI)
|
actions.register(setUI, cache=False)
|
||||||
|
|
||||||
|
|
||||||
def getUsers(data):
|
def getUsers(data):
|
||||||
|
|
Loading…
Reference in a new issue