-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified submit due to most of its functionality being moved to utils
- Loading branch information
Showing
1 changed file
with
30 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
import os | ||
import click | ||
from temmies.themis import Themis | ||
from temmies.exercise_group import ExerciseGroup | ||
from .utils import load_metadata | ||
|
||
|
||
def submit_file(files, quiet): | ||
"""Submit file(s) to the relevant assignment.""" | ||
# Check for .temmies file | ||
if not os.path.exists('.temmies'): | ||
click.echo("No .temmies file found in the current directory. Please run 'temmies init' first.", err=True) | ||
metadata = load_metadata() | ||
if not metadata: | ||
return | ||
|
||
# Load assignment metadata | ||
with open('.temmies', 'r') as f: | ||
metadata = dict(line.strip().split('=') for line in f) | ||
assignment_id = metadata.get('assignment_id') | ||
user = metadata.get('username') | ||
if not assignment_id or not user: | ||
click.echo("Assignment ID or username not found in .temmies file.", err=True) | ||
return | ||
username = metadata.get('username') | ||
assignment_path = metadata.get('assignment_path') | ||
|
||
# Authenticate the user using the username from .temmies | ||
themis = Themis(user) | ||
|
||
# Retrieve the assignment object | ||
assignment = themis.get_assignment_by_id(assignment_id) | ||
if not assignment: | ||
click.echo("Assignment not found. Please ensure you're in the correct directory.", err=True) | ||
return | ||
themis = Themis(username) | ||
assignment = ExerciseGroup( | ||
themis.session, | ||
assignment_path, | ||
title='', | ||
parent=None, | ||
submitable=True | ||
) | ||
|
||
# Submit each file | ||
for file in files: | ||
if not os.path.exists(file): | ||
click.echo(f"File '{file}' does not exist.", err=True) | ||
continue | ||
with open(file, 'rb') as f: | ||
content = f.read() | ||
click.echo(f"Submitting file: {file}") | ||
result = assignment.submit_file(file_name=file, content=content) | ||
if not quiet: | ||
click.echo(f"Submission result for {file}: {result}") | ||
click.echo("Submission complete.") | ||
# TODO: Test this | ||
submission = assignment.submit(list(files)) | ||
if not quiet: | ||
click.echo("Submission results:") | ||
status = submission.get_status() | ||
click.echo(f"- Status: {status}") | ||
results = submission.get_results() | ||
if results: | ||
for case, result in results.items(): | ||
status_text = "Passed" if result.get('passed') else "Failed" | ||
click.echo(f"Test Case {case}: {status_text}") |