def printDevInfo(dict_dev): if not dict_dev: return mode = 'bold' fore = 'black' fore_error = 'white' back = 'green' back_default = 'green' back_error = 'red' back_change = 'yellow' x = 1 y = 3 for k in dict_dev: string, index, state = dict_dev[k] if state == 1: back = back_change elif state == -1: back = back_error fore = fore_error else: back = back_default string = info_template % (k, string) myprint.printHLine(x, y + index, myprint.terminal_width, ' ', mode, fore, back, False) myprint.printString(x, y + index, string, mode, fore, back, False) sys.stdout.flush()
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 printDevInfo(dict_dev): if not dict_dev: return mode = 'bold' fore = 'black' fore_error = 'white' back = 'green' back_default = 'green' back_error = 'red' back_change = 'yellow' x = 1 y = 3 for k in dict_dev: string, index, state = dict_dev[k] if state == 1: back = back_change elif state == -1: back = back_error fore = fore_error else: back = back_default string = info_template % (k, string) myprint.printHLine(x, y+index, myprint.terminal_width, ' ', mode, fore, back, False) myprint.printString(x, y+index, string, mode, fore, back, False) sys.stdout.flush()
def printTitle(dev_num, dev_error_num, cnt, reboot): x = 1 y = 1 mode = 'bold' fore = 'white' back = 'green' title = title_temp % (dev_error_num, dev_num, cnt, reboot) myprint.printHLine(x, y, myprint.terminal_width, ' ', mode, fore, back, False) myprint.printString(x + 2, y, title, mode, fore, back)
def initTitle(dev_id, time_interval, num_test): global len_title mode = 'bold' fore = 'white' back = 'green' title = title_template_ % (dev_id, time_interval) len_title = len(title) title = title_template % (dev_id, time_interval, num_test) myprint.printHLine(1, 1, myprint.terminal_width, ' ', mode, fore, back) myprint.printString(1, 1, title, mode, fore, back)
def printUnknowIP(unknow_ip, len_dev): mode = 'bold' fore = 'white' back = 'blue' x = 1 y = len_dev + 3 for index, info in enumerate(unknow_ip): string = "%s : %s" % info myprint.printHLine(x, y+index, myprint.terminal_width, ' ', mode, fore, back, False) myprint.printString(x, y+index, string, mode, fore, back, False) myprint.moveCursor(0, myprint.terminal_hight) sys.stdout.flush()
def printScale(y): len_old = -2 for i in range(cup_scale_min, cup_scale_max+1): len_f = float((i - cup_scale_min)) / (cup_scale_max - cup_scale_min) * myprint.terminal_width len_f = int(len_f) if len_f == 0: len_f = 1 if len_f-len_old > 1: myprint.printString(len_f, y+1, str(i)[-1]) if len(str(i)) > 2: myprint.printString(len_f, y, str(i)[-2]) len_old = len_f
def printUnknowIP(unknow_ip, len_dev): mode = 'bold' fore = 'white' back = 'blue' x = 1 y = len_dev + 3 for index, info in enumerate(unknow_ip): string = "%s : %s" % info myprint.printHLine(x, y + index, myprint.terminal_width, ' ', mode, fore, back, False) myprint.printString(x, y + index, string, mode, fore, back, False) myprint.moveCursor(0, myprint.terminal_hight) sys.stdout.flush()
def printScale(y): len_old = -2 for i in range(cup_scale_min, cup_scale_max + 1): len_f = float( (i - cup_scale_min)) / (cup_scale_max - cup_scale_min) * myprint.terminal_width len_f = int(len_f) if len_f == 0: len_f = 1 if len_f - len_old > 1: myprint.printString(len_f, y + 1, str(i)[-1]) if len(str(i)) > 2: myprint.printString(len_f, y, str(i)[-2]) len_old = len_f
def printInfo(value_left, value_right): mode = '' fore = '' back = '' x = 1 y = 3 cup1_x = len("value_left: ") cup1_y = 5 cup2_x = len("value_left: xxxx, value_right: ") cup2_y = 5 myprint.printHLine(x, y, myprint.terminal_width, ' ', mode, fore, back) string = info_template % (str(value_left), str(value_right)) myprint.printString(x, y, string, mode, fore, back) printCup(cup1_x, cup1_y, value_left) printCup(cup2_x, cup2_y, value_right)
def printInfo(value_left, value_right, show_other=False): global len_f_left_old global len_f_right_old mode = '' fore = '' back = '' x = 1 y = myprint.terminal_hight - 6 cup1_y = myprint.terminal_hight - 1 cup2_y = myprint.terminal_hight string = info_template % (str(value_left), str(value_right)) myprint.printString(x, y, string, mode, fore, back, False) if show_other: printScale(cup1_y-2) len_f_left_old = printCup(cup1_y, value_left, len_f_left_old, show_other) len_f_right_old = printCup(cup2_y, value_right, len_f_right_old, show_other) myprint.moveCursor(1, 4) sys.stdout.flush()
def printPowerMater(value_left, value_right): global len_f_left_old global len_f_right_old mode = '' fore = '' back = '' x = 1 y = myprint.terminal_hight - 2 cup1_y = y + 1 cup2_y = y + 2 string = info_template % (str(value_left), str(value_right)) myprint.printString(x, y, string, mode, fore, back, False) myprint.hideCursor() len_f_left_old = printCup(cup1_y, value_left, len_f_left_old) len_f_right_old = printCup(cup2_y, value_right, len_f_right_old) myprint.showCursor() # myprint.moveCursor(1, y-1) sys.stdout.flush()
def printInfo(value_left, value_right, show_other=False): global len_f_left_old global len_f_right_old mode = '' fore = '' back = '' x = 1 y = myprint.terminal_hight - 6 cup1_y = myprint.terminal_hight - 1 cup2_y = myprint.terminal_hight string = info_template % (str(value_left), str(value_right)) myprint.printString(x, y, string, mode, fore, back, False) if show_other: printScale(cup1_y - 2) len_f_left_old = printCup(cup1_y, value_left, len_f_left_old, show_other) len_f_right_old = printCup(cup2_y, value_right, len_f_right_old, show_other) myprint.moveCursor(1, 4) sys.stdout.flush()
def printInfo(dev_id, dev_info, num, state): mode = 'bold' fore = 'black' fore_error = 'white' back = 'green' back_error = 'red' back_change = 'yellow' x = 1 y = 3 if state == 1: back = back_change elif state == -1: fore = fore_error back = back_error myprint.printHLine(x, y+num, myprint.terminal_width, ' ', mode, fore, back, False) string = info_template % (str(dev_id), str(dev_info)) myprint.printString(x, y+num, string, mode, fore, back, False) myprint.moveCursor(0, myprint.terminal_hight) sys.stdout.flush()
def printCup(x, y, value): ch = ' ' mode = '' fore = 'white' back = 'green' hight = len(cup_scale) hight_have = None if value is None: value = cup_scale[-1] else: value = float(value) # value = -20.0 for i in range(hight): myprint.printString(x, y+i, "%-d" % cup_scale[i]) if hight_have is None and cup_scale[i] < value: hight_have = i myprint.printVLine(x+3, y, hight, ch, mode, fore, fore) if hight_have is not None: myprint.printVLine(x+3, y+hight_have, hight-hight_have, ch, mode, fore, back)
def printInfo(dev_id, dev_info, num, state): mode = 'bold' fore = 'black' fore_error = 'white' back = 'green' back_error = 'red' back_change = 'yellow' x = 1 y = 3 if state == 1: back = back_change elif state == -1: fore = fore_error back = back_error myprint.printHLine(x, y + num, myprint.terminal_width, ' ', mode, fore, back, False) string = info_template % (str(dev_id), str(dev_info)) myprint.printString(x, y + num, string, mode, fore, back, False) myprint.moveCursor(0, myprint.terminal_hight) sys.stdout.flush()
def printTitle(num_test): mode = 'bold' fore = 'white' back = 'green' s = "[%d]" % num_test myprint.printString(len_title + 1, 1, s, mode, fore, back)
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()
def printTitle(num_test): mode = 'bold' fore = 'white' back = 'green' s = "[%d]" % num_test myprint.printString(len_title+1, 1, s, mode, fore, back)