def __handle_created_event(self, folder): """ Creates an index by finding the name of the new filesystem :param folder: :return: """ username, isAnonymous = self.__handle_event(folder) with self.app.app_context(): user = User(username, anonymous=isAnonymous) user_service = UserDataService(user) user_service.build_index()
def __handle_deleted_event(self, folder): """ Destroys the index by finding the name of the deleted filesystem :param folder: :return: """ username, isAnonymous = self.__handle_event(folder) with self.app.app_context(): user = User.get(username) user_service = UserDataService(user) user_service.destroy_index() del User.users[username]
def build_all(): """ Build new index for all users """ total = UserDataService.index_all_users() data = dict(status='ok', jobs=total, description='{total} jobs created'.format(total=total)) return jsonify(data), 200
def sync_all(): """ Sync the filesystem and ES DB by scanning and comparing datastructures on both the filesystem and ES DB. """ total = UserDataService.sync_all_users() data = dict(status='ok', jobs=total, description='{total} jobs created'.format(total=total)) return jsonify(data), 200
def sync_users(): """ Create a new index if a new filesystem is found and sync it. Delete the index if the filesystem has been removed. """ home_path = app.config['USER_HOME_PATH'] temp_path = app.config['USER_TEMP_PATH'] users = [(o, False) for o in os.listdir(home_path) if ( os.path.isdir(home_path + '/' + o) and not os.path.islink(home_path + '/' + o))] users += [(o, True) for o in os.listdir(temp_path) if ( os.path.isdir(temp_path + '/' + o) and not os.path.islink(temp_path + '/' + o))] new_users = set(users) - set(User.users.keys()) deleted_users = set(User.users.keys()) - set(users) for user in new_users: user_obj = User(user[0], anonymous=user[1]) service = UserDataService(user_obj) service.build_index() app.logger.info(u"Added user: {u}. Is anonymous: {isAno}" .format(u=user[0], isAno=user[1])) for user in deleted_users: service = UserDataService(User.get(user[0])) service.destroy_index() del User.users[user[0]] app.logger.info(u"Deleted user: {u}.".format(u=user[0]))
def index_all_users_job(): with APP.app_context(): UserDataService.sync_all_users()