trigger fs scan after changing path, move folder if new path does not exist, fixes #214

This commit is contained in:
j 2016-01-27 11:58:11 +05:30
parent 2e04379838
commit e27e429fd6
3 changed files with 25 additions and 4 deletions

View file

@ -43,6 +43,7 @@ def remove_missing():
dirty = True
if dirty:
state.db.session.commit()
state.cache.clear('group:')
for f in File.query:
if not state.tasks.connected:
return
@ -107,6 +108,17 @@ def run_scan():
added += 1
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):
options = options or {}
logger.debug('run_import')

View file

@ -29,7 +29,9 @@ class Tasks(Thread):
try:
action, data = m
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)
elif action == 'getpreview':
get_preview(data)

View file

@ -66,6 +66,11 @@ def setPreferences(data):
data['contact'] != settings.preferences['contact']
change_username = 'username' in data and \
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)
if 'username' in data:
u = state.user()
@ -75,8 +80,10 @@ def setPreferences(data):
Changelog.record(u, 'editusername', data['username'])
if change_contact:
Changelog.record(state.user(), 'editcontact', data['contact'])
if change_path:
state.tasks.queue('changelibrarypath', change_path)
return settings.preferences
actions.register(setPreferences)
actions.register(setPreferences, cache=False)
def resetUI(data):
'''
@ -88,7 +95,7 @@ def resetUI(data):
os.unlink(ui_json)
settings.ui = settings.pdict(ui_json, settings.config['user']['ui'])
return settings.ui
actions.register(resetUI)
actions.register(resetUI, cache=False)
def setUI(data):
'''
@ -99,7 +106,7 @@ def setUI(data):
'''
update_dict(settings.ui, data)
return settings.ui
actions.register(setUI)
actions.register(setUI, cache=False)
def getUsers(data):