hpc-cluster/smart-data/smartGUI.py

172 lines
5.8 KiB
Python

#!/usr/bin/python3
from tkinter import *
import os
# Die folgende Funktion soll ausgeführt werden, wenn
# der Benutzer den Button anklickt
def button_searchSerial():
entry_text = eingabefeld.get()
info_field.delete('1.0', END)
if (entry_text == ""):
info_field.insert(END, "Please enter Serial.")
else:
#info_field.config(text="found text")
Exist = 0
# get all subfolders
subfolders = [f.path for f in os.scandir("./") if f.is_dir() ]
#scan each subfolder for Serial
for folder in subfolders:
files = os.listdir(folder)
for filenames in files:
File_name = folder + "/" + filenames
if File_name.find(entry_text) != -1:
Exist = 1
Smart_file = open(File_name,"r")
Smart_data = Smart_file.read().splitlines()
# wenn Checkbox Total Runtime gewählt
if PowerOnHours.get() or RawReadErrorRate.get():
info1 = Smart_data[59]+"\n"
info_field.insert(END, info1)
if RawReadErrorRate.get():
info2 = Smart_data[60]+"\n"
info_field.insert(END, info2)
if PowerOnHours.get():
info3 = Smart_data[65]+"\n"
info_field.insert(END, info3)
else:
# wenn keine Checkbox gewählt, alle daten
scroll.config(command=info_field.yview)
info_field.config(yscrollcommand=scroll.set)
for line in Smart_data:
text = line + "\n"
info_field.insert(END, text)
Smart_file.close()
if Exist == 0:
info_field.insert(END, "Serial not known")
def button_searchMultiple():
entry_figure = eingabefeld_RawReadErrorRate.get()
entry_Prop = ChoiceVar.get()
info_field.delete('1.0', END)
if (entry_Prop == ""):
info_field.insert(END, "Please select Property.")
if (entry_figure == ""):
info_field.insert(END, "Please enter Figures.")
else:
#info_field.config(text="found text")
Exist = 0
# get all subfolders
subfolders = [f.path for f in os.scandir("./") if f.is_dir() ]
for folder in subfolders:
files = os.listdir(folder)
for filenames in files:
File_name = folder + "/" + filenames
Smart_file = open(File_name,"r")
Smart_data = Smart_file.read().splitlines()
if entry_Prop == "Raw_Read_Error_Rate":
Smart_prop = Smart_data[60]
elif entry_Prop == "Reallocated_Sector_Ct":
Smart_prop = Smart_data[63]
elif entry_Prop == "Reallocated_Event_Count":
Smart_prop = Smart_data[72]
elif entry_Prop == "Current_Pending_Sector":
Smart_prop = Smart_data[73]
PropValueStr = Smart_prop[87:len(Smart_prop)]
if float(PropValueStr) > float(entry_figure):
Exist = 1
text = File_name + " - " + entry_Prop + " " + PropValueStr + "\n"
info_field.insert(END, text)
Smart_file.close()
if Exist == 0:
info_field.insert(END, "No Serial found")
# Ein Fenster erstellen
fenster = Tk()
# Den Fenstertitle erstellen
fenster.title("SmartData")
fenster.geometry("1000x1000")
# Label und Buttons erstellen.
SearchSerial = Label(fenster, text="Search for one Serial:", font='Arial 14 bold')
Search_button = Button(fenster, text="Suchen", command=button_searchSerial)
exit_button = Button(fenster, text="Beenden", command=fenster.quit)
Serial_label = Label(fenster, text="Serial: ")
# Hier kann der Benutzer eine Eingabe machen
eingabefeld = Entry(fenster, bd=5)
# Nun fügen wir die Komponenten unserem Fenster
# in der gwünschten Reihenfolge hinzu.
SearchSerial.place(x=0,y=0)
Serial_label.place(x=10, y = 30, width = 50, height = 40)
eingabefeld.place(x=70, y=30, width = 200, height = 40)
Search_button.place(x=280, y = 30, width = 100, height = 40)
exit_button.place(x=860, y=930 , width = 100, height = 40)
# Checkboxen
PowerOnHours = IntVar()
chk_PowerOnHours = Checkbutton(fenster, text = "Power On Hours", variable = PowerOnHours)
chk_PowerOnHours.place(x=400, y = 30, height = 40)
RawReadErrorRate = IntVar()
chk_RawReadErrorRate = Checkbutton(fenster, text = "Raw Read Error Rate", variable = RawReadErrorRate)
chk_RawReadErrorRate.place(x=550, y = 30, height = 40)
#Search multiple
SearchMultiple = Label(fenster, text="Search for Multiple:", font='Arial 14 bold')
SearchMultiple.place(x=0,y=90)
choices ={"Raw_Read_Error_Rate", "Reallocated_Sector_Ct", "Reallocated_Event_Count", "Current_Pending_Sector"}
ChoiceVar = StringVar(fenster)
ChoiceVar.set(" ")
ChoiceMenu = OptionMenu(fenster, ChoiceVar, *choices)
ChoiceMenu.place(x=10,y=120, width = 250, height = 40)
Choice_label = Label(fenster, text=">")
Choice_label.place(x=260, y=120, width=50, height = 40)
eingabefeld_RawReadErrorRate = Entry(fenster, bd=5)
eingabefeld_RawReadErrorRate.place(x=320, y=120, width=100, height = 40)
Search_button_Multiple = Button(fenster, text="Suchen", command=button_searchMultiple)
Search_button_Multiple.place(x=420, y = 120, width = 100, height = 40)
# Feld für Informationen
info_field = Text(fenster)
info_field.place(x=50, y=200, width=885, height=700)
scroll = Scrollbar(fenster)
scroll.place(x=935, y=200, width = 15, height=700)
# In der Ereignisschleife auf Eingabe des Benutzers warten.
fenster.mainloop()