def printInfo(devices_id, num, test_items, stat_dict): x = 1 y = 3 mode = 'bold' fore = 'white' back = 'blue' fore_error = 'red' dev_id = devices_id[num] dev_stat = stat_dict[dev_id] string = '' str_dev = dev_id total_error = dev_stat['Total'] if total_error > 0: str_dev += '[%d]' % total_error str_dev = myprint.useStyle(str_dev, mode, fore_error, back) else: str_dev = myprint.useStyle(str_dev, mode, fore, back) string += str_dev + '\t' for item in test_items: str_tmp = item cnt_error = dev_stat[item] if cnt_error > 0: str_tmp += '[%d]' % cnt_error str_tmp = myprint.useStyle(str_tmp, mode, fore_error, back) else: str_tmp = myprint.useStyle(str_tmp, mode, fore, back) string += str_tmp + '\t' myprint.printHLine(x, y+num, myprint.terminal_width, ' ', mode, fore, back, False) myprint.printString(x, y+num, string) myprint.moveCursor(0, myprint.terminal_hight) sys.stdout.flush()
def outputInfo(string, level='debug'): global logger global flag_output level = level.strip() level = level.lower() if not str_style.has_key(level): level = 'debug' style = str_style[level] string = myprint.useStyle(string, style['mode'], style['fore'], style['back']) if flag_output: print string
def printInfo_plus(devices_id, num, test_items, stat_dict, stat_dict_old): x = 1 y = 3 y_cur = y mode = 'bold' fore = 'white' fore_title = fore fore_error = 'red' fore_select = fore back = 'blue' back_title = 'green' back_error = back back_select = 'yellow' title_devid = 'DeviceID' num_next = num + 1 if num >= len(devices_id)-1: num_next = 0 dev_id = devices_id[num] dev_stat = stat_dict[dev_id] len_max_devid = max(len(title_devid), len(dev_id)) + 2 list_len_max = map(lambda x: len(x)+2, test_items) list_len_max = [len_max_devid] + list_len_max str_row = '+' for line in list_len_max: str_row += '-' * line + '+' str_row = myprint.useStyle(str_row, mode, fore_title, back_title) title_list = [title_devid] + test_items str_title = '|' for field, len_max in zip(title_list, list_len_max): field = ' ' + str(field) + ' ' str_title += str(field).ljust(len_max) + '|' str_title = myprint.useStyle(str_title, mode, fore_title, back_title) myprint.printString(x, y_cur, str_row) y_cur += 1 myprint.printString(x, y_cur, str_title) y_cur += 1 myprint.printString(x, y_cur, str_row) y_cur += 1 for index, dev_id in enumerate(devices_id): dev_stat = stat_dict[dev_id] line = '' str_node_out = '' fore_cur = fore back_cur = back if index == num_next: str_node_out = myprint.useStyle('|', mode, fore_select, back_select) # str_node = myprint.useStyle('|', mode, fore_select, back_select) fore_cur = fore_select back_cur = back_select else: str_node_out = myprint.useStyle('|', mode, fore_title, back_title) str_node = myprint.useStyle('|', mode, fore_cur, back_cur) line += str_node_out str_tmp = ' ' + str(dev_id) + ' ' str_tmp = str_tmp.ljust(len_max_devid) if dev_stat['Total'] > 0: str_tmp = myprint.useStyle(str_tmp, mode, fore_error, back_cur) else: str_tmp = myprint.useStyle(str_tmp, mode, fore_cur, back_cur) line += str_tmp + str_node for i, item in enumerate(test_items): cnt_error = dev_stat[item] len_max = list_len_max[i+1] str_tmp = ' ' + str(cnt_error) + ' ' str_tmp = str_tmp.ljust(len_max) if cnt_error == 0 or (stat_dict_old[dev_id][item] == cnt_error): # if cnt_error > 0: str_tmp = myprint.useStyle(str_tmp, mode, fore_cur, back_cur) else: str_tmp = myprint.useStyle(str_tmp, mode, fore_error, back_cur) line += str_tmp if i != len(test_items)-1: line += str_node line += str_node_out myprint.printString(x, y_cur, line) y_cur += 1 myprint.printString(x, y_cur, str_row) myprint.moveCursor(0, myprint.terminal_hight) sys.stdout.flush()