diff --git a/oml/item/scan.py b/oml/item/scan.py index 3a0de75..14a95b1 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -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') diff --git a/oml/tasks.py b/oml/tasks.py index b389306..88946c2 100644 --- a/oml/tasks.py +++ b/oml/tasks.py @@ -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) diff --git a/oml/user/api.py b/oml/user/api.py index f785e9b..509d821 100644 --- a/oml/user/api.py +++ b/oml/user/api.py @@ -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):