-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
84 lines (72 loc) · 2.03 KB
/
main.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
#!/usr/bin/python
#
# This file is part of the BotWars-Client program.
# Copyright (C) 2013 Suhail Sherif, Rajat Khanduja
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import re
from BotWarsServer import *
import validators
usage='''
python main.py <server ip> <server port> <teamname> <teampassword> <command+>
where command+ is one of:
submit <problem number> <filename>
ask <problem number> <doubt>
leaderboard
score
'''
def main(args):
serverIP=args[0]
if not validators.validIP(serverIP):
print "Invalid server IP"
return
serverPort=args[1]
try:
int(serverPort)
except ValueError:
print "Invalid server port"
return
server = BotWarsServer(serverIP+":"+serverPort)
teamName=args[2]
teamPassword=args[3]
if args[4]=="submit":
if len(args)<7:
print usage
return
problemNumber = args[5]
fileName = args[6]
if not validators.validFile(fileName):
print "Invalid filename"
return
server.submit(teamName, teamPassword, problemNumber, fileName)
elif args[4]=="ask":
if len(args)<6:
print usage
return
problemNumber = args[5]
doubt = reduce(lambda x,y: x+" "+y, args[6:])
server.ask(teamName, teamPassword, problemNumber, doubt)
elif args[4]=="leaderboard":
server.getLeaderboard(teamName, teamPassword)
elif args[4]=="score":
server.getScore(teamName, teamPassword)
else:
print usage
return
if __name__=="__main__":
if len(sys.argv)<6:
print usage
else:
main(sys.argv[1:])