Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unzipping submissions on submission #406

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions backend/project/endpoints/submissions/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
19 changes: 11 additions & 8 deletions backend/project/utils/submissions/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

bash /tests/run_test.sh
bash /tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ fi

echo "Running tests..."
ls /submission
bash /tests/run_test.sh
bash /tests/run_tests.sh