-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradebot.py
More file actions
139 lines (108 loc) · 3.97 KB
/
gradebot.py
File metadata and controls
139 lines (108 loc) · 3.97 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os
import re
def main():
print("Welcome to Grader 1.0!")
#Get the Path of th directory to grade
path = input("Enter Path: ")
while not (os.path.isdir(path)):
path = input("Path does not exist please try again: ")
"""#Get grading python or java
com = input("Are you grading python or java? (python/java): "):
while not (com == "python" or com == "java"):
com = input("Not valid language please try again (python/java): "):
"""
neededFiles = input("Enter location of other files needed (.java) ")
neededFiles = path + "/" + neededFiles
while not (os.path.isdir(neededFiles)):
inputFiles = input("Location does not exist please try again: ")
inputFiles = path + "/" + inputFiles
"""
gradeType = input("Is the program run using a main driver, piped .txt input or .txt as an argument? (m/p/a): "):
while(gradeType == "m" or gradeType =="p" or gradeType == "a"):
gradeType = input("Please try again. (m/p/a): "):
if(gradeType == "m"):
mainDriver(com, path)
else if (gradeType == "p"):
pipedInput(com, path)
else:
textArg(com, path)
"""
inputFiles = input("Enter location of input (.txt) files: ")
inputFiles = path + "/" + inputFiles
while not (os.path.isdir(inputFiles)):
inputFiles = input("Location does not exist please try again: ")
inputFiles = path + "/" + inputFiles
solOutput = input("Enter location of solution output (.txt) files: ")
solOutput = path + "/" + solOutput
while not (os.path.isdir(solOutput)):
solOutput = input("Location does not exist please try again: ")
solOutput = path + "/" + solOutput
main = input("Name of Main java class (not including .java): ")
while(True):
student = findAndCompileStudent(path, neededFiles, inputFiles)
runTests(student,main,inputFiles)
compareOutputs(solOutput, student)
again = input("Run again with same config? (y/n): ")
if again == 'y':
continue
break
"""
def mainDriver(com, path):
main = input("Name of Main " + com + " File: ")
command = com + " " + main
extra = ""
"""
"""
@param path - The path to the directory of the lab being graded
@param neededFiles - path to the directory to the files needed to run the program
@param inputFiles - path to the input textFiles
"""
def findAndCompileStudent(path, neededFiles, inputFiles):
while(True):
stu = str(input("Enter Student to Grade (Folder Name): "))
stu = path + "/" + stu
if(os.path.isdir(stu)):
print("Student Exists! Compiling Code!")
break
else:
print("Student does not exist try again!")
for file in os.listdir(neededFiles):
os.system("cp " + str(neededFiles) + "/" + file + " " + stu)
os.system("find " + stu + " -name '*.java' | xargs javac")
for file in os.listdir(inputFiles):
os.system("cp " + str(inputFiles) + "/" + file + " " + stu)
return stu
"""
@param stu - The path to the students directory
@param main - Name of the main driver file
@param inputFiles - path to the input textFiles
Calls diff on the students output vs the faculty output
"""
def runTests(stu, main, inputFiles):
os.system("mkdir " + stu + "/stu-output")
os.system("find stu-output -name '*.txt' | xargs rm")
num = -1
command = "java -classpath " + stu + " " + main + " "
for file in os.listdir(inputFiles):
number = re.search(r'\d+', file).group()
print(str(number))
print("RUNNING " + file)
os.system(command + inputFiles + "/" + str(file) + " > "+ stu +"/stu-output/output" + str(number) +".txt")
"""
@param sol - Location of the solution files
@param path - The path to the students directory
Calls diff on the students output vs the faculty output
"""
def compareOutputs(sol, path):
for solfile in os.listdir(sol):
for stufile in os.listdir(path + "/stu-output"):
if ".txt" not in stufile:
continue
number = re.search(r'\d+', solfile).group()
stuNumber = re.search(r'\d+', stufile).group()
if not number == stuNumber:
continue
print("Comparing Test " + number)
os.system("diff " + path + "/stu-output/" + str(stufile) + " " + sol + "/" + str(solfile))
input("Continue?")
main()