This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
give.py
76 lines (63 loc) · 2.49 KB
/
give.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import argparse
import time
from colorama import Fore
import localtestcommon as c
def runSubmissions(tests, course, project, ssh, verbose):
t_pass = 0
t_fail = 0
for t in tests:
print(f"Submitting exercise: {t['name']} ({t['identifier']})... ", end='', flush=True)
output = c.runCommand(ssh, c.TEMP_FOLDER, f"echo $'yes\\nyes' | give cs{course} {project}_{t['identifier']} {' '.join(t['files'])}")
doOutput = verbose is not None
if len(output[0]):
if "Your submission is ACCEPTED" in output[0][-1]:
print(Fore.GREEN + "Accepted!")
t_pass += 1
else:
print(Fore.RED + "Declined")
doOutput = True
t_fail += 1
else:
print(Fore.RED + "Declined")
doOutput = True
t_fail += 1
if doOutput:
c.printOutput(output)
print(Fore.RESET)
if t_fail == 0:
print(Fore.GREEN + "All exercises submitted!!!")
else:
print(Fore.RED + f"{t_fail} failed to submit, " + Fore.GREEN + f"{t_pass} accepted" + Fore.RESET)
print(Fore.RESET, end='')
print("Displaying course submissions in browser...")
time.sleep(0.5)
c.viewSubmissions(course, c.UNSW_TERM)
def main(args):
config = c.getJson()
parser = argparse.ArgumentParser(prog="localtest give", description="Submit work for UNSW CSE courses")
parser.add_argument("exercises", type=str, default=None, nargs="*")
parser.add_argument("-v", "--verbose", action="count")
parsed = parser.parse_args(args)
arg_tests = parsed.exercises
verbosity = parsed.verbose
print(f"Course: {config['course']}, Project: {config['project']}")
if len(arg_tests) == 0:
print("Submitting all exercises")
sub_list = config["exercises"]
else:
sub_list = []
for t in config["exercises"]:
if t["identifier"] in arg_tests:
sub_list.append(t)
arg_tests.remove(t["identifier"])
if len(arg_tests) > 0:
print(f"Unable to find definitions for {len(arg_tests)} exercises(s):")
for t in arg_tests:
print(" - " + t)
usr, pwd = c.getZidPass()
# Prompt for agreement
c.uploadFiles(usr, pwd, c.TEMP_FOLDER)
ssh = c.createSsh(usr, pwd)
runSubmissions(sub_list, config["course"], config["project"], ssh, verbosity)
c.removeFiles(ssh, c.TEMP_FOLDER)
ssh.close()