from picasso import Picasso from logger import scanner_logger, tester_logger, mem_logger, stresser_logger from . import data_manager import pydoc import re from os import listdir class ShowLOG(object): def __init__(self, dialog_config): self.dialog_config = dialog_config self.diag_ui = Picasso() def start(self): # show log menu log_info_resp, log_checked_list = self.set_show_log_items() if log_info_resp is False: return False log_file = "" # list log in log path and filter with selected log type item = log_checked_list[0] rex = re.compile(item) # generate log list with the lastest in the first log_list = sorted(filter(rex.search, listdir(data_manager._log_dir)), reverse = True) if not log_list: print 'No log file' return False # generate the log file tuple list for radiolist dialog displaying choices_list = [] prefix_index = 'a' for log in log_list: show_str = "{}.".format(prefix_index) choices_list.append((show_str, log, False)) prefix_index = chr(ord(prefix_index) + 1) # check the first item by default list_t = list(choices_list[0]) list_t[2] = True choices_list[0] = tuple(list_t) # display the log file select dialog resp, checked_item = self.diag_ui.show_radiolist_dialog( title = 'Logs', msg = 'Please select a log to display', choices = choices_list) # set the log file name with log path if resp == 'ok': for log in choices_list: if log[0] == checked_item: log_file = '{0}/{1}'.format(data_manager._log_dir, log[1]) elif resp == 'cancel': return False # display the log file name print "************************ [{}] **************".format(log_file) # read in the log with open(log_file, 'r') as log: log_txt = log.read() # display the log via pager less_cmd = 'less -Ps"SPACE\: Page Down\, q\: Quit"' pydoc.pipepager(log_txt, less_cmd) def stop(self): pass def set_show_log_items(self): log_info_resp, log_checked_list = self.diag_ui.show_dialog_from_file( self.dialog_config, "show_menu") if (log_info_resp == 'cancel' or log_info_resp == 'esc'): return False, None return True, log_checked_list