Exemple #1
0
 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]))
Exemple #2
0
def list_all(uid):
    """
    List data from the specified user
    """
    user = User.get(uid)
    data = UserDataService(user).find_all_folders()
    return jsonify(data)
Exemple #3
0
def destroy(uid):
    user = User.get(uid)
    if user:
        zfs_service = ZFSService(uid)
        data = zfs_service.destroy(user)
        if data is not True:
            abort(500, data['error'])
        return jsonify(data)
    abort(404, USER_ERROR_MSG.format(u=uid))
Exemple #4
0
def destroy_idx(uid):
    """
    Destroy index for the specified user.
    """
    warnings.warn(("This function shouldn't be used, instead this application "
                   "should automatically find the deleted filesystem and "
                   "destroy its index."), DeprecationWarning)
    user = User.get(uid)
    if user:
        return jsonify(EsService().destroy_index(user.uid))
    abort(404, USER_ERROR_MSG.format(u=uid))
Exemple #5
0
 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]
Exemple #6
0
def create(uid):
    """
    Create new index for the specified user.
    :param uid:
    """
    warnings.warn(("This function shouldn't be used, instead this application "
                   "should automatically find the new filesystem and create "
                   "the index for it."), DeprecationWarning)
    user = User.get(uid)
    if user:
        return jsonify(EsService().create_index(user.uid, overwrite=True))
    abort(404, USER_ERROR_MSG.format(u=uid))
Exemple #7
0
def sync_folder(uid, node_id):
    """
    Sync the folder by comparing datastructures on both the filesystem and the
    ES DB.
    """
    user = User.get(uid)
    if user:
        try:
            TS(folder_sync_process, user=user, node_id=node_id)
        except ValueError, error:
            app.logger.error(error)
            return jsonify(dict(error='job is already running')), 200
        data = dict(status='job created')
        return jsonify(data), 201
Exemple #8
0
def sync_uid(uid):
    """
    Sync the filesystem and ES DB by scanning and comparing datastructures
    on both the filesystem and ES DB.
    """
    user = User.get(uid)
    if user:
        try:
            TS(full_sync_process, user=user)
        except ValueError, error:
            app.logger.error(error)
            return jsonify(dict(error='job is already running')), 200
        data = dict(status='job created')
        return jsonify(data), 201
Exemple #9
0
def build(uid):
    """
    Build new index for the specified user, build folders first and then
    later fill it with files. This function is heavy, so it executes
    asynchronously.
    """
    user = User.get(uid)
    if user:
        try:
            TS(build_process, user=user)
        except ValueError, error:
            app.logger.error(error)
            return jsonify(dict(error='job is already running')), 200
        data = dict(status='job created')
        return jsonify(data), 201
Exemple #10
0
def list_all():
    """list all devices"""
    data = UserDataService(User.get('olav')).find_all()
    return jsonify(data)