Skip to content

Commit

Permalink
Simplified submit due to most of its functionality being moved to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
confestim committed Nov 18, 2024
1 parent 22bf4a2 commit 7ca8a58
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions temmies_cli/commands/submit.py
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}")

0 comments on commit 7ca8a58

Please sign in to comment.