-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
80 lines (72 loc) · 2.37 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
import sys
import time
from utils import *
from Client import Client
c = Client()
c.start_probe_listener()
c.discover_offer_makers()
clear()
while True:
print_header("AVAILABLE COMMANDS")
commands = [
"Refresh servers",
"Select a file",
"Show results",
"List available Offerers",
"Quit"
]
for i, command in enumerate(commands):
print("\t", change_style(str(i + 1) + ")", 'bold'), " ", command)
option = input("\n" + change_style("Please enter your command", 'underline') + ": ")
if option=="1":
clear()
print_header("Refresh servers")
c.discover_offer_makers()
print('-' * 89)
pass
elif option=="2":
clear()
print_header("Select a file")
filepath = input("\n" + change_style("Enter absolute file path", 'underline') + ": ")
number_of_ops = input("\n" + change_style("How many operations are there in file?", 'underline') + ": ")
duration = input("\n" + change_style("How many seconds do these take?", 'underline') + ": ")
clear()
print("Waiting for the script offer to complete")
c.broadcast_script_offer(filepath, int(duration), int(number_of_ops))
print("Script offer sent")
input("Press enter to continue")
pass
elif option=="3":
clear()
print_header("Show results")
if c.offer is None:
print("No offer and results are present at this time\n")
print("Press Enter to continue\n")
input()
clear()
continue
success, result = c.offer.get_results()
print(c.offer.get_offsets())
if success:
print(result)
else:
print("Could not complete operation successfully")
print("\nPress Enter to continue")
input()
clear()
elif option == "4":
clear()
print_header("List available servers")
for server in c.available_servers.values():
print(server)
print("\nPress Enter to continue")
input()
clear()
elif option=="5":
clear()
print_notification("Good bye \n\n")
os.system("pkill -9 \"python3 main.py\"")
sys.exit(0)
else:
clear()
print_error("Invalid option")