From 7ca8a581490cadb21f3451f78fe148a1825d5bc1 Mon Sep 17 00:00:00 2001 From: Boyan Date: Mon, 18 Nov 2024 20:26:19 +0100 Subject: [PATCH] Simplified submit due to most of its functionality being moved to utils --- temmies_cli/commands/submit.py | 61 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/temmies_cli/commands/submit.py b/temmies_cli/commands/submit.py index 6ff2494..7adbcb1 100644 --- a/temmies_cli/commands/submit.py +++ b/temmies_cli/commands/submit.py @@ -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}")