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
/
localtest.py
120 lines (107 loc) · 4.33 KB
/
localtest.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/python3
"""CSE Localtest: A program so you don't need to use VLab again
Author: Miguel Guthridge
All contributions welcome
"""
import sys
import os
from colorama import Fore
from colorama import Fore
import localtestcommon as c
import test, give, projectsetup
def badArgs():
print(f"Run `localtest help` for help")
exit()
def help():
r = Fore.RESET
d = Fore.RED
b = Fore.CYAN
m = Fore.MAGENTA
y = Fore.YELLOW
l = Fore.BLUE
print('\n'.join([
f"{b}localtest{r}: A program so that you don't need to VLab anymore",
f"",
f"Commands:",
f" {y}*{r} {b}help{r}: Display this message",
f" {y}*{r} {b}setup{r}: Generate required files for using localtest with a project",
f" and fetch starter code if necessary",
f" Args:",
f" {y}*{r} {b}course{r}: course code (eg {m}1511{r})",
f" {y}*{r} {b}project{r}: project to start (eg {m}lab01{r})",
f" Run {b}localtest setup default{r} to use a template project",
f" definition (for tests and exams)",
f" {y}*{r} {b}fetch{r}: Fetch starter code (use this after setting up a custom template)",
f" {y}*{r} {b}instruct{r}: Launch instructions for project in web browser",
f" {y}*{r} {b}subs{r}: View course submissions in a web browser",
f" {y}*{r} {b}test{r}: Run autotests on project",
f" Args:",
f" {y}*{r} {b}exercises{r}: specific exercises to test (defaults to all)",
f" {y}*{r} {b}give{r}: Submit code from project",
f" Args:",
f" {y}*{r} {b}exercises{r}: specific exercises to submit (defaults to all)",
f" {y}*{r} {b}upload{r}: Uploads the contents of the directory to VLab",
f" {y}*{r} {b}update{r}: Runs a {b}git pull{r} to update the repository provided that it",
f" was {b}git clone{r}d",
f"Note that for most commands, a {b}-v{r} argument will cause all output to be displayed",
f"(eg. {b}test{r} or {b}give{r} output), even if it succeeded",
f""
]))
print('\n'.join([
f"{r}NOTICE{r}: this program is provided in the hope that it will be useful,",
f"however, although all reasonable efforts have been made to ensure it works,",
f"no guarantees are made that it is flawless or infallible.",
f"{d}This software is not endorsed by UNSW, and as such, you use it at your",
f"own risk{r}. However, all feedback and contributions towards improving",
f"the software would be greatly appreciated. Feel free to contribute setups",
f"for your courses, or improvements to the app's functionality.",
f""
]))
print(f"GitHub: {l}{c.PROJECT_GITHUB}{r}")
print(f"Version: {m}{c.VERSION}{r}")
print(f"Setups library version: {m}{c.SETUPS_VERSION}{r}")
print(f"Author: {b}Miguel Guthridge{r}")
def projecthelp():
proj = c.getJson()
try:
c.launchURL(proj["help_url"])
except KeyError:
print(f"Error: help URL not found for this project ({proj['course']}_{proj['project']})")
def viewSubmissions():
proj = c.getJson()
c.viewSubmissions(proj["course"], c.UNSW_TERM)
def upload():
usr, pwd = c.getZidPass()
c.uploadFiles(usr, pwd, c.UPLOAD_FOLDER)
def update():
print("Updating localtest...")
os.chdir(os.path.dirname(__file__))
os.system("git pull")
if __name__ == "__main__":
try:
if len(sys.argv) < 2:
badArgs()
if sys.argv[1] == "test":
test.main(sys.argv[2:])
elif sys.argv[1] == "give":
give.main(sys.argv[2:])
elif sys.argv[1] == "setup":
projectsetup.main(sys.argv[2:])
elif sys.argv[1] == "fetch":
projectsetup.mainFetch(sys.argv[2:])
elif sys.argv[1] == "instruct":
projecthelp()
elif sys.argv[1] == "subs":
viewSubmissions()
elif sys.argv[1] == "help":
help()
elif sys.argv[1] == "upload":
upload()
elif sys.argv[1] == "update":
update()
else:
badArgs()
except KeyboardInterrupt:
print(Fore.RED)
print("Operation interrupted! Exiting...")
print(Fore.RESET)