From eb3823418cf816b2517a5eb924b68baeeff06383 Mon Sep 17 00:00:00 2001 From: Etienne Boileau Date: Wed, 22 May 2024 10:05:55 +0200 Subject: [PATCH] WIP #47 FIX upload path --- server/src/scimodom/api/dataset.py | 7 +++++-- server/src/scimodom/services/comparison.py | 7 +++---- server/src/scimodom/services/file.py | 5 +---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/server/src/scimodom/api/dataset.py b/server/src/scimodom/api/dataset.py index ce23b2ca..38312216 100644 --- a/server/src/scimodom/api/dataset.py +++ b/server/src/scimodom/api/dataset.py @@ -1,9 +1,11 @@ import logging +from pathlib import Path from flask import Blueprint, request from flask_cors import cross_origin from flask_jwt_extended import jwt_required, get_jwt_identity +from scimodom.config import Config from scimodom.services.comparison import ( get_comparison_service, FailedUploadError, @@ -43,14 +45,15 @@ def is_true(value): reference_ids = request.args.getlist("reference", type=str) comparison_ids = request.args.getlist("comparison", type=str) - upload_path = request.args.get("upload", type=str) + upload_id = request.args.get("upload", type=str) operation = request.args.get("operation", type=str) is_strand = request.args.get("strand", type=is_true) is_euf = request.args.get("euf", type=is_true) comparison_service = get_comparison_service(operation, is_strand) - if upload_path: + if upload_id: try: + upload_path = Path(Config.UPLOAD_PATH, upload_id) comparison_service.upload_records(upload_path, is_euf) except FileNotFoundError as exc: return ( diff --git a/server/src/scimodom/services/comparison.py b/server/src/scimodom/services/comparison.py index 2ea4e1e1..8f5e4c86 100644 --- a/server/src/scimodom/services/comparison.py +++ b/server/src/scimodom/services/comparison.py @@ -155,15 +155,14 @@ def _construct_query(idx: str): raise NoRecordsFoundError self._comparison_records.append(records) - def upload_records(self, upload: str, is_euf: bool): + def upload_records(self, upload_path: Path, is_euf: bool): """Upload records. - :param upload: Uploaded dataset to compare - :type upload: str | Path + :param upload_path: Uploaded dataset to compare + :type upload_path: Path :param is_euf: BED6 or bedRMod (EUF) :type is_euf: bool """ - upload_path = Path(upload) if not upload_path.is_file(): msg = f"No such file or directory: {upload_path.as_posix()}" raise FileNotFoundError(msg) diff --git a/server/src/scimodom/services/file.py b/server/src/scimodom/services/file.py index c7c9acd9..8ddba358 100644 --- a/server/src/scimodom/services/file.py +++ b/server/src/scimodom/services/file.py @@ -30,10 +30,7 @@ def __init__(self, session: Session): # general def upload_tmp_file(self, stream, max_file_size): - parent = join(Config.DATA_PATH, "tmp") - if not exists(parent): - makedirs(parent) - fp, path = mkstemp(dir=parent) + fp, path = mkstemp(dir=Config.UPLOAD_PATH) close(fp) file_id = basename(path) self._stream_to_file(stream, path, max_file_size, overwrite_is_ok=True)