Skip to content

Commit

Permalink
WIP #47 FIX upload path
Browse files Browse the repository at this point in the history
  • Loading branch information
eboileau committed May 22, 2024
1 parent 42b6130 commit eb38234
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 5 additions & 2 deletions server/src/scimodom/api/dataset.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 (
Expand Down
7 changes: 3 additions & 4 deletions server/src/scimodom/services/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions server/src/scimodom/services/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eb38234

Please sign in to comment.