From cba824f61ad1d1dc489a54a3919351ffa956234c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 8 Jan 2024 11:25:37 +0300 Subject: Fix errors with types. --- qc_app/upload/rqtl2.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'qc_app/upload') diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index 53e7f3f..d60ea65 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -103,6 +103,9 @@ def create_population(species_id: int): pgsrc="create-population"), code=307) +class __RequestError__(Exception): #pylint: disable=[invalid-name] + """Internal class to avoid pylint's `too-many-return-statements` error.""" + @rqtl2.route(("/upload/species//population/" "/rqtl2-bundle"), methods=["GET", "POST"]) @@ -133,22 +136,21 @@ def upload_rqtl2_bundle(species_id: int, population_id: int): species=species, population=population) + if not bool(request.files.get("rqtl2_bundle")): + raise __RequestError__("No R/qtl2 zip bundle provided.") + the_file = save_file( - request.files.get("rqtl2_bundle"), Path(app.config["UPLOAD_FOLDER"])) + request.files["rqtl2_bundle"], Path(app.config["UPLOAD_FOLDER"])) if not bool(the_file): - flash("Please provide a valid R/qtl2 zip bundle.", - "alert-error alert-danger error-rqtl2") - return this_page_with_errors + raise __RequestError__("Please provide a valid R/qtl2 zip bundle.") - if not is_zipfile(the_file): - flash("Invalid file! Expected a zip file.", - "alert-error alert-danger error-rqtl2") - return this_page_with_errors + if not is_zipfile(str(the_file)): + raise __RequestError__("Invalid file! Expected a zip file.") try: - with ZipFile(the_file, "r") as zfile: + with ZipFile(str(the_file), "r") as zfile: r_qtl2.validate_bundle(zfile) return "WOULD PROCESS THE BUNDLE..." - except InvalidFormat as invf: - flash("".join(invf.args), "alert-error alert-danger error-rqtl2") + except (InvalidFormat, __RequestError__) as exc: + flash("".join(exc.args), "alert-error alert-danger error-rqtl2") return this_page_with_errors -- cgit v1.2.3