-
Notifications
You must be signed in to change notification settings - Fork 0
/
rankHelper.py
85 lines (72 loc) · 1.71 KB
/
rankHelper.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
import os
from rankHelperDb import *
db = None
#Configuration
netFile = "netFile.csv"
rankFile = "rankFile.csv"
def checkValidName(args):
if len(args) == 1:
name = args[0]
print db.checkValidName(name)
else:
print "Invalid arguments. Usage: checkValidNames <name>"
def newRank(args):
if len(args) < 1:
print "No arguments provided. Usage: newRank <name1>,<name2>,<name3>,<name4>"
else:
for net in args:
if not db.checkValidName(net):
print "Error: Invalid name " + net
return
db.newRank(args)
def save():
db.writeRanksToFile(rankFile)
def printSummary():
print "Ranks:"
db.printRanks()
print ""
print "Nets:"
db.printNets()
def checkRank(args):
if len(args) <= 1:
print "Invalid arguments. Usage: check <name1>,<name2>,<name3>,<name4>"
else:
for net in args:
if not db.checkValidName(net):
print "Error: Invalid name " + net
return
print db.checkRank(args)
if __name__ == "__main__":
#Prepare files
os.system('touch ' + netFile)
os.system('touch ' + rankFile)
#Instantiate rankHelperDb
db = rankHelperDb()
db.loadNets(netFile)
db.loadRanks(rankFile)
#Start command prompt while loop
keepGoing = True
while keepGoing:
line = raw_input(" > ")
line = line.split()
command = line[0]
args = " ".join(line[1:])
args = args.split(",")
for arg in args:
arg = arg.strip()
if command == "q" or command == "Q" or command == "quit":
print "Saving..."
save()
keepGoing = False
elif command == 'checkValidName':
checkValidName(args)
elif command == 'newRank':
newRank(args)
elif command == 'save':
save()
elif command == 'summary':
printSummary()
elif command == 'check':
checkRank(args)
else:
print "Command " + command + " not found."