-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.py
119 lines (103 loc) · 2.87 KB
/
submit.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
# submit.py (client)
#
# (c) 2015 George Wong
#
from __future__ import print_function
import subprocess
import socket
import sys
####
SERVER_ADDR = 'cso15.jinyangli.com'
SERVER_PORT = 5000
VERBOSE = False
####
def run_test(name, data):
return subprocess.check_output(["./" + name, str(data)])
if __name__ == "__main__":
STUDENT = {
"name" : "",
"netid" : "",
"nid" : "",
"cc" : "",
"full" : ""
}
print("")
## Ensure we have a meaningful program to run
if len(sys.argv) < 2:
print("Please run this program with the proper arguments:")
print(" python submit.py <sample>\n")
exit(-3)
## Get the student info
try:
fp = open("my.info","r")
for line in fp:
STUDENT["full"] += line
if line.strip()[:5].lower() == "name:":
STUDENT["name"] = line.strip()[5:].strip()
elif line.strip()[:7].lower() == "net id:":
STUDENT["netid"] = line.strip()[7:].strip()
elif line.strip()[:11].lower() == "nyu id(n#):":
STUDENT["nid"] = line.strip()[11:].strip()
elif line.strip()[:18].lower() == "confirmation code:":
STUDENT["cc"] = line.strip()[18:].strip()
fp.close()
except:
print("Unable to open my.info file. Quitting!\n")
exit(-1)
# Validate
valid = 1
if len(STUDENT["name"]) < 1:
valid = 0
print("No name found")
if len(STUDENT["netid"]) < 1:
valid = 0
print("No net id found")
if len(STUDENT["nid"]) < 1:
valid = 0
print("No N# found")
if len(STUDENT["cc"]) < 1:
print("No confirmation code found")
valid = 0
if valid == 0:
print(" + Please check your my.info file!\n")
exit(-5)
## Attempt to establish connection with server
print("Waiting on free connection...")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((SERVER_ADDR, SERVER_PORT))
s.send("HELO")
s.recv(64)
s.send(STUDENT["name"])
s.recv(64)
s.send(STUDENT["netid"])
s.recv(64)
s.send(STUDENT["nid"])
s.recv(64)
s.send(STUDENT["cc"])
r = s.recv(1024)
if r != "GOOD":
print("Server does not like your credentials. Please")
print("verify your information and try again.\n")
exit(-2)
s.send(STUDENT["full"])
s.send(sys.argv[1])
if s.recv(1024) != "ACK":
print("Bad test name. Please ensure you are following the")
print("correct naming convention!\n")
exit(-3)
# Run tests
tests_passed = 0
ntests = int(s.recv(1024))
if VERBOSE: print("Beginning " + str(ntests) + " tests")
for i in range(ntests):
print('Running {0:5.1f}%'.format(100.*i/ntests), end='\r')
sys.stdout.flush()
arg = int(s.recv(1024))
out = run_test(sys.argv[1],arg)
s.send(out)
valid = s.recv(1024)
if valid == "valid": tests_passed += 1
print('Running {0:5.1f}%'.format(100.))
## Notify submitter of result
s.close()
print('Tests passed: {0:d} of {1:d}\n'.format(tests_passed, ntests))