diff --git a/backend/project/endpoints/submissions/submissions.py b/backend/project/endpoints/submissions/submissions.py index a47ca63b..b03490fe 100644 --- a/backend/project/endpoints/submissions/submissions.py +++ b/backend/project/endpoints/submissions/submissions.py @@ -7,6 +7,7 @@ from datetime import datetime from zoneinfo import ZoneInfo from shutil import rmtree +import zipfile from flask import request from flask_restful import Resource from sqlalchemy import exc, and_ @@ -104,7 +105,7 @@ def get(self, uid=None) -> dict[str, any]: return data, 500 @authorize_student_submission - def post(self, uid=None) -> dict[str, any]: + def post(self, uid=None) -> dict[str, any]: # pylint: disable=too-many-locals, too-many-branches, too-many-statements """Post a new submission to a project Returns: @@ -174,7 +175,13 @@ def post(self, uid=None) -> dict[str, any]: input_folder = path.join(submission.submission_path, "submission") makedirs(input_folder, exist_ok=True) for file in files: - file.save(path.join(input_folder, file.filename)) + file_path = path.join(input_folder, file.filename) + file.save(file_path) + if file.filename.endswith(".zip"): + with zipfile.ZipFile(file_path) as upload_zip: + upload_zip.extractall(input_folder) + + except OSError: rmtree(submission.submission_path) session.rollback() diff --git a/backend/project/utils/submissions/evaluator.py b/backend/project/utils/submissions/evaluator.py index 4a772cdd..50e75dc0 100644 --- a/backend/project/utils/submissions/evaluator.py +++ b/backend/project/utils/submissions/evaluator.py @@ -82,15 +82,18 @@ def run_evaluator(submission: Submission, project_path: str, evaluator: str, is_ Returns: int: The exit code of the evaluator. """ - status_code = evaluate(submission, project_path, evaluator, is_late) - - if not is_late: - if status_code == 0: - submission.submission_status = 'SUCCESS' + try: + status_code = evaluate(submission, project_path, evaluator, is_late) + if not is_late: + if status_code == 0: + submission.submission_status = 'SUCCESS' + else: + submission.submission_status = 'FAIL' else: - submission.submission_status = 'FAIL' - else: - submission.submission_status = 'LATE' + submission.submission_status = 'LATE' + except: # pylint: disable=bare-except + submission.submission_status = 'FAIL' + try: db.session.merge(submission) diff --git a/backend/project/utils/submissions/evaluators/general/entry_point.sh b/backend/project/utils/submissions/evaluators/general/entry_point.sh index 9cdc7a66..51758446 100644 --- a/backend/project/utils/submissions/evaluators/general/entry_point.sh +++ b/backend/project/utils/submissions/evaluators/general/entry_point.sh @@ -1,3 +1,3 @@ #!/bin/bash -bash /tests/run_test.sh +bash /tests/run_tests.sh diff --git a/backend/project/utils/submissions/evaluators/python/entry_point.sh b/backend/project/utils/submissions/evaluators/python/entry_point.sh index e24a883a..4518c789 100644 --- a/backend/project/utils/submissions/evaluators/python/entry_point.sh +++ b/backend/project/utils/submissions/evaluators/python/entry_point.sh @@ -37,4 +37,4 @@ fi echo "Running tests..." ls /submission -bash /tests/run_test.sh \ No newline at end of file +bash /tests/run_tests.sh \ No newline at end of file diff --git a/backend/tests/utils/submission_evaluators/resources/python/tc_1/assignment/run_test.sh b/backend/tests/utils/submission_evaluators/resources/python/tc_1/assignment/run_tests.sh similarity index 100% rename from backend/tests/utils/submission_evaluators/resources/python/tc_1/assignment/run_test.sh rename to backend/tests/utils/submission_evaluators/resources/python/tc_1/assignment/run_tests.sh diff --git a/backend/tests/utils/submission_evaluators/resources/python/tc_2/assignment/run_test.sh b/backend/tests/utils/submission_evaluators/resources/python/tc_2/assignment/run_tests.sh similarity index 100% rename from backend/tests/utils/submission_evaluators/resources/python/tc_2/assignment/run_test.sh rename to backend/tests/utils/submission_evaluators/resources/python/tc_2/assignment/run_tests.sh diff --git a/backend/tests/utils/submission_evaluators/resources/python/tc_3/assignment/run_test.sh b/backend/tests/utils/submission_evaluators/resources/python/tc_3/assignment/run_tests.sh similarity index 100% rename from backend/tests/utils/submission_evaluators/resources/python/tc_3/assignment/run_test.sh rename to backend/tests/utils/submission_evaluators/resources/python/tc_3/assignment/run_tests.sh