-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAB_Control.py
132 lines (103 loc) · 4.48 KB
/
LAB_Control.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
127
128
129
130
131
132
import customtkinter as ctk
from CTkMessagebox import CTkMessagebox
import asyncio
import websockets
import json
ctk.set_appearance_mode("Dark")
ctk.set_default_color_theme("blue")
LAB_IPS = {
'IT Lab': [
["192.168.1.10", "192.168.1.11", "192.168.1.12"],
["192.168.1.13", "192.168.1.14"],
["192.168.1.15"]
],
'CS Lab': [
["192.168.2.10", "192.168.2.11", "192.168.2.12"],
["192.168.2.13", "192.168.2.14"],
["192.168.2.15"]
]
}
LOCAL_SOFTWARE_JSON = "software_list.json"
async def send_request(ip_address, command):
uri = f"ws://{ip_address}:35369"
try:
async with websockets.connect(uri) as websocket:
await websocket.send(command)
except (asyncio.TimeoutError, Exception):
pass
async def send_requests_to_group(ip_group, command):
tasks = [send_request(ip, command) for ip in ip_group]
await asyncio.gather(*tasks)
await asyncio.sleep(3)
def fetch_software_list():
try:
with open(LOCAL_SOFTWARE_JSON, "r") as file:
return json.load(file)
except (FileNotFoundError, json.JSONDecodeError) as e:
CTkMessagebox(title="Error", message=f"Failed to load software list: {e}", icon="error")
return {}
def on_install_button_click():
selected_lab = lab_combobox.get()
selected_semester = semester_combobox.get()
if not selected_lab:
CTkMessagebox(title="Warning", message="Please select a lab", icon="warning")
return
if not selected_semester:
CTkMessagebox(title="Warning", message="Please select a software package", icon="warning")
return
if not acknowledge_var.get():
CTkMessagebox(title="Warning", message="Please acknowledge", icon="warning")
return
command = f"download:{selected_semester}"
ip_groups = LAB_IPS[selected_lab]
for ip_group in ip_groups:
asyncio.run(send_requests_to_group(ip_group, command))
CTkMessagebox(title="Info", message="Download requests sent successfully", icon="info")
def on_update_button_click():
CTkMessagebox(title="Update", message="Update functionality is not implemented yet.", icon="info")
def on_list_softwares_button_click():
software_list = fetch_software_list()
selected_semester = semester_combobox.get()
if not selected_semester:
CTkMessagebox(title="Warning", message="Please select a software package", icon="warning")
return
semester_softwares = software_list.get(selected_semester, [])
if not semester_softwares:
CTkMessagebox(title="Info", message="No software available for this semester.", icon="info")
return
software_display = "\n".join(semester_softwares)
CTkMessagebox(title="Software List", message=f"List of software packages for {selected_semester}:\n\n{software_display}", icon="info")
root = ctk.CTk()
root.title("Automated Software Installer")
root.geometry("800x600")
center_frame = ctk.CTkFrame(root, corner_radius=10, fg_color="transparent")
center_frame.pack(pady=20, padx=20, fill="both", expand=True)
font_large = ctk.CTkFont(size=18, weight="bold")
font_medium = ctk.CTkFont(size=14)
lab_label = ctk.CTkLabel(center_frame, text="Select Lab", font=font_large)
lab_label.pack(pady=10)
lab_combobox = ctk.CTkComboBox(center_frame, values=list(LAB_IPS.keys()), width=300, state="readonly")
lab_combobox.pack(pady=10)
semester_label = ctk.CTkLabel(center_frame, text="Software Package:", font=font_large)
semester_label.pack(pady=10)
software_list = fetch_software_list()
semesters = list(software_list.keys())
semester_combobox = ctk.CTkComboBox(center_frame, values=semesters, width=300, state="readonly")
semester_combobox.pack(pady=10)
acknowledge_var = ctk.BooleanVar()
acknowledge_checkbutton = ctk.CTkCheckBox(
center_frame,
text="I acknowledge the above software will be installed",
variable=acknowledge_var,
font=font_medium
)
acknowledge_checkbutton.pack(pady=10)
buttons_frame = ctk.CTkFrame(center_frame, fg_color="transparent")
buttons_frame.pack(pady=20)
install_button = ctk.CTkButton(buttons_frame, text="Install", command=on_install_button_click, font=font_large)
install_button.pack(side="left", padx=10)
update_button = ctk.CTkButton(buttons_frame, text="Update", command=on_update_button_click, font=font_large)
update_button.pack(side="left", padx=10)
list_softwares_button = ctk.CTkButton(buttons_frame, text="List Softwares", command=on_list_softwares_button_click, font=font_large)
list_softwares_button.pack(side="left", padx=10)
root.mainloop()