-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cli.py
64 lines (58 loc) · 2.1 KB
/
Cli.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
from threading import Thread
import os
from Util import get_node_by_addr
class Cli(Thread):
def __init__(self, api):
Thread.__init__(self)
print("Client created")
self.api = api
def process_command(self, cmd):
args = cmd.split()
if len(args) == 0:
args = [""]
if args[0] == 'join':
self.api.join(args[1])
self.api.setStatus(True)
print("Joined. You're online, lucky!")
elif args[0] == "logoff":
status = self.api.getStatus()
if status:
self.api.leave()
out = "You're logged off. Bye."
else:
out = "Hey! You're already offline. What do you want from me?"
print(out)
elif args[0] == "exit":
out = "Self-destruction program started. We will never see each other again =( "
print(out)
os._exit(1)
elif args[0] == "elections":
print("Elections started")
self.api.runBully()
elif args[0] == "show":
print(self.api.getNetworkMembers())
elif args[0] == "master":
print("Master node is " + self.api.getMasterAddress())
elif args[0] == "fun":
print("Having fun right now")
self.api.adventureTime(False)
elif args[0] == "agrawala":
print("Having agrawalafun right now")
self.api.adventureTime(True)
elif args[0] == "ms":
self.api.checkMasterAvaliability()
print("Master string is " + self.api.getMasterString())
elif args[0] == "cleanms":
get_node_by_addr(self.api.getMasterAddress()).setMasterString("")
print("Cleaned master string")
else:
print("Unknown command. Check the manual")
def run(self):
print("Client started")
while True:
print("Enter your command")
cmd = input()
try:
self.process_command(cmd)
except:
print("Something went wrong, please contact Microsoft support")