Exemplo n.º 1
0
    def main(self):
        """Upload the files"""
        for file_name in os.listdir(self.args.files_directory):
            file_path = os.path.join(self.args.files_directory, file_name)
            file_size = os.path.getsize(file_path)
            file_path_on_askomics = None
            file_ext = os.path.splitext(file_name)[1]

            files = FilesHandler(self.application, self.session)

            fp = open(file_path)
            first = True
            for (last, chunk) in self.generator_is_last(
                    self.read_in_chunks(fp, self.chunk_size)):
                data = {
                    "first": first,
                    "last": last,
                    "chunk": chunk,
                    "path": file_path_on_askomics,
                    "name": file_name,
                    "size": file_size,
                    "type": files.get_type(file_ext)
                }
                first = False
                file_path_on_askomics = files.persist_chunk(data)
Exemplo n.º 2
0
def upload_chunk():
    """Upload a file chunk

    Returns
    -------
    json
        path: name of the local file. To append the next chunk into it
        error: True if error, else False
        errorMessage: the error message of error, else an empty string
    """
    files_utils = FilesUtils(current_app, session)
    disk_space = files_utils.get_size_occupied_by_user(
    ) if "user" in session else None

    if session["user"]["quota"] > 0 and disk_space >= session["user"]["quota"]:
        return jsonify({
            'errorMessage': "Exceeded quota",
            "path": '',
            "error": True
        }), 400

    data = request.get_json()
    if not (data and all([
            key in data for key in
        ["first", "last", "size", "name", "type", "size", "chunk"]
    ])):
        return jsonify({
            "path": '',
            "error": True,
            "errorMessage": "Missing parameters"
        }), 400

    if not (data["first"] or data.get("path")):
        return jsonify({
            "path": '',
            "error": True,
            "errorMessage": "Missing path parameter"
        }), 400

    try:
        files = FilesHandler(current_app, session)
        path = files.persist_chunk(data)
    except Exception as e:
        traceback.print_exc(file=sys.stdout)
        return jsonify({
            "path": '',
            "error": True,
            "errorMessage": str(e)
        }), 500
    return jsonify({"path": path, "error": False, "errorMessage": ""})
Exemplo n.º 3
0
    def upload_file(self, file_path):
        """Summary

        Parameters
        ----------
        file_path : TYPE
            Description

        Returns
        -------
        TYPE
            Description
        """
        file_name = file_path.split("/")[-1]
        file_extension = os.path.splitext(file_path)[1]

        file_type = {
            ".tsv": "text/tab-separated-values",
            ".csv": "text/tab-separated-values",
            ".gff3": "null",
            ".bed": "null"
        }

        with open(file_path, 'r') as file_content:
            content = file_content.read()

        file_data = {
            "first": True,
            "last": True,
            "chunk": content,
            "name": file_name,
            "type": file_type[file_extension],
            "size": os.path.getsize(file_path)
        }

        files = FilesHandler(self.app, self.session)
        filepath = files.persist_chunk(file_data)
        filedate = files.date

        return {
            "file_path": filepath,
            "file_date": filedate
        }