-
Notifications
You must be signed in to change notification settings - Fork 1
/
terminal.py
127 lines (95 loc) · 3.26 KB
/
terminal.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
import server.useCasesAPI as useCasesAPI
import server.parser as parser
import server.timer as timer
from server.commonFunctions import readFile, unixTime
from server.storage import storage
#kek
def isInt(x):
try:
y = int(x)
except ValueError:
return False
return True
while (True):
try:
line = input()
except KeyboardInterrupt:
break
params = line.split()
command = params[0]
if (command == 'look'):
if (len(params) < 3 or (not isInt(params[2]))):
continue
if (params[1][0] == 'u'):
id = int(params[2])
resp = storage.getUser(id)
if (params[1][0] == 'p'):
id = int(params[2])
resp = storage.getProblem(id)
if (params[1][0] == 's'):
id = int(params[2])
resp = storage.getSubmission(id)
if (params[1][0] == 't'):
id = int(params[2])
resp = storage.getTournament(id)
if (resp is not None):
resp.print()
if (command == 'add'):
if (len(params) < 2):
continue
if (params[1][0] == 's'):
if (len(params) < 5):
continue
if ((not isInt(params[2])) or (not isInt(params[3]))):
continue
filename = params[4]
userId = int(params[2])
problemId = int(params[3])
useCasesAPI.addSubmission(userId, problemId, readFile(params[4]))
if (params[1][0] == 'u'):
if (len(params) < 4):
continue
useCasesAPI.addUser(params[2], params[3])
if (command == 'ch'):
if (len(params) < 3 or (not isInt(params[1])) or (not isInt(params[2]))):
continue
useCasesAPI.changeMainSubmission(int(params[1]), int(params[2]))
if (command == 'tour'):
if (len(params) < 2 or (not isInt(params[1]))):
continue
probId = int(params[1])
useCasesAPI.tournament(probId)
if (command == 'judge'):
if (len(params) < 3 or (not isInt(params[1])) or (not isInt(params[2]))):
continue
id1 = int(params[1])
id2 = int(params[2])
invocationResult = useCasesAPI.judge(id1, id2)
print(invocationResult.results[0].goodStr())
print(invocationResult.results[1].goodStr())
if (command == 'problemset'):
res = storage.getProblemset()
print(res)
if (command == 'subs'):
if (len(params) == 2 and isInt(params[1])):
res = storage.getSubmissionListU(int(params[1]))
print(res)
if (len(params) == 3 and isInt(params[1]) and isInt(params[2])):
res = storage.getSubmissionListUP(int(params[1]), int(params[2]))
print(res)
if (command == 'parse'):
if (len(params) == 2):
print(parser.parseArchive(params[1]))
if (command == 'time'):
print(unixTime())
if (command == 'upd'):
timer.update()
if (command == 'delayTour'):
if (len(params) < 3 or not(isInt(params[1])) or not(isInt(params[2]))):
continue
try:
useCasesAPI.createDelayedTournament(int(params[1]), int(params[2]))
except:
pass
if (command == 'close'):
break