Ejemplo n.º 1
0
    def createFile(self, fileName, size):
        '''check filename existence'''
        files = [f for f in self.__LFiles if f.fileName == fileName]
        if len(files) > 0:
            return False

        newFile = File()
        newFile.fileName = fileName
        newFile.fileSize = size
        sizeleft = size
        for i in range(self.__block_count):
            block = self.__blocks[i]
            if block.getState() == Block.States["Free"] or block.getState(
            ) == Block.States["Transparent"] or block.getState(
            ) == Block.States["Free_and_Overwritten"]:
                newFile.blocks.append(i)
                sizeleft = sizeleft - Block.BlockSize
                if sizeleft <= 0:
                    break
        if sizeleft > 0:
            return False
        for i in range(len(newFile.blocks)):
            self.__blocks[newFile.blocks[i]].processOperation("write")
        self.__LFiles.append(newFile)
        return True
Ejemplo n.º 2
0
def download_file():
    if request.method == 'POST':
        response = UserModel.get_user_from_session(request.headers.get('SessionId'))
        if response['Status'] == 200:
            json_query = request.get_json()
            return FileModel.download_file_s3(json_query['File'])
    return json.dumps(response)
Ejemplo n.º 3
0
def upload_change_obj():
    if request.method == 'POST':
        response = UserModel.get_user_from_session(
            request.headers.get('SessionId'))
        if response['Status'] == 200:
            submitted_file = request.files['file']
            file_obj = FileModel(submitted_file)
            file_valid_response = file_obj.check_file_extension()
            if file_valid_response['Status'] == 200:
                file_obj.upload_file_landing()
                file_path = file_obj.upload_file_s3()
                file_obj.delete_file_landing()
                if file_path is not None:
                    response = {
                        'Status': 201,
                        'Filepath': file_path,
                        'Message': 'Successfully uploaded'
                    }
                else:
                    response = {
                        'Status': 201,
                        'FileName': file_obj.file_name,
                        'Message': 'Could not upload file'
                    }
        return json.dumps(response)
Ejemplo n.º 4
0
 def createFile(self,fileName,size):
     '''check filename existence'''
     files = [f for f in self.__LFiles if f.fileName==fileName]
     if len(files) > 0:
         return False;
     
     newFile = File();
     newFile.fileName = fileName
     newFile.fileSize = size
     sizeleft = size;
     for i in range(self.__block_count):
         block = self.__blocks[i]
         if block.getState() == Block.States["Free"] or block.getState() == Block.States["Transparent"] or block.getState() == Block.States["Free_and_Overwritten"]:
             newFile.blocks.append(i)
             sizeleft = sizeleft - Block.BlockSize;
             if sizeleft <= 0:
                 break
     if sizeleft > 0:
         return False
     for i in range(len(newFile.blocks)):
         self.__blocks[newFile.blocks[i]].processOperation("write")
     self.__LFiles.append(newFile)
     return True;
Ejemplo n.º 5
0
def upload_files():
    if request.method == 'POST':
        response = UserModel.get_user_from_session(
            request.headers.get('SessionId'))
        if response['Status'] == 200:
            submitted_files = request.files
            dataset_id = generate_unique_identifier()
            response = {'Status': 201, 'DataSetId': dataset_id, 'Files': []}
            for file in submitted_files.keys():
                file_id = generate_unique_identifier()
                file_obj = FileModel(submitted_files[file])
                file_valid_response = file_obj.check_file_extension()
                if file_valid_response['Status'] == 200:
                    file_obj.upload_file_landing()
                    file_path = file_obj.upload_dataset_file_s3(
                        dataset_id, file_id)
                    if file_path is not None:
                        file_obj.delete_file_landing()
                        response['Files'].append({
                            'FileId':
                            file_id,
                            'FileName':
                            file_obj.file_name,
                            'Message':
                            'Successfully uploaded'
                        })
                    else:
                        response['Files'].append({
                            'FileId':
                            file_id,
                            'FileName':
                            file_obj.file_name,
                            'Message':
                            'Could not upload to S3'
                        })
                else:
                    response['Files'].append({
                        'Status':
                        file_valid_response['Status'],
                        'FileId':
                        file_id,
                        'Message':
                        file_valid_response['Message']
                    })
            return json.dumps(response)
        else:
            return response
Ejemplo n.º 6
0
from Model.RbTree import Tree
import random as r
from Model.File import File

f = File()
f.load()

f.remove("c")