-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrade.py
156 lines (132 loc) · 4.36 KB
/
Grade.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"""
File: Grade.py
Author: Thomas Cenova
Description:
Simple script to successively go through each python script in a folder
Must be run with folder to look in in same directory
"""
import sys
import os
"""
Function to return a list of folder contents
:param path string of path to folder
:return list of strings of the files in the folder
"""
def getFolderContents(path):
return os.listdir(path)
"""
Function to run a python script from within this script
NOTE: assumes you can run a python script by calling the file itself
"""
def runPythonScript(folder, name):
command = ""
slash = "\\"
if sys.platform != "win32":
command = "python3 "
slash = "/"
command += "\"" + os.getcwd() + slash + folder + slash + name + "\""
os.system(command)
def runWithShellScript(pathToShellScript, folder, nameOfFileToRun):
slash = "\\"
if sys.platform != "win32":
command = "python3 "
slash = "/"
command = "sh " + pathToShellScript + " "
command += os.getcwd() + slash + folder + slash + nameOfFileToRun
os.system(command)
"""
Function that prints instructions on usage and commands
"""
def howToUse():
print("Commands are: \n"
" STOP - stops program \n"
" GOTO fileNumber - goes to that file number \n"
" BACK - goes to last file run \n"
" LIST - lists all files in folder ")
def findLibPath():
if sys.platform == "win32":
for element in sys.path:
if element[-3:] == "lib":
return element
else:
return "idle3 "
"""
"""
def runInIDLE(folder, name, libPath):
if sys.platform == "win32":
command = libPath + "\\idlelib\\idle "
slash = "\\"
else:
command = "idle3 "
slash = "/"
command = command + "\"" + os.getcwd() + slash + folder + slash + name + "\""
if sys.platform != "win32":
command += " &"
os.system(command)
"""
"""
def runSequence(path, file):
while True:
if (input("Enter to run, Anything else to end: ")==""):
runPythonScript(path, file)
else:
return
"""
"""
def main(argv):
if len(argv) > 1:
print("Usage: Grade.py folderName")
return
howToUse()
libPath = findLibPath()
#print(str(sys.path) + " HAHA")
path = argv[0]
files = getFolderContents(path)
files.sort()
fileNumber = 0;
while (fileNumber<len(files)+1):
goodCMD = False
while (goodCMD == False):
if fileNumber<len(files):
print("Currently at file: \n" + "#: " + str(fileNumber) + "\tName: " + files[fileNumber])
else:
print("End of files")
entered = input("Please enter command or hit enter to continue\n>>>")
cmdList = entered.split()
if (fileNumber>len(files)-1):
return
if cmdList == []:
goodCMD = True
else:
CMD = cmdList[0].upper()
if CMD == "GOTO":
try:
fileNumber = int(cmdList[1])
print("Going to " + cmdList[1])
except:
print ("Usage: GOTO filenumber")
elif CMD == "BACK":
if fileNumber > 0:
fileNumber -= 1
else:
print("Cannot go back")
elif CMD == "STOP":
return
elif CMD == "LIST":
print("Folder Contents:"
"#\tFilename")
for x in range (0, len(files)-1):
print(str(x) + "\t" + files[x])
elif CMD == "SKIP":
fileNumber += 1
elif CMD == "HELP":
howToUse()
print("Running :" + files[fileNumber])
runInIDLE(path, files[fileNumber], libPath)
input("Press ENTER to run program")
#runSequence(path, files[fileNumber])
runWithShellScript("runTests.sh", path, files[fileNumber])
fileNumber += 1
#run main only if run file directly
if __name__ == '__main__':
main(sys.argv[1:])