From 57d02816cfcacbf9835495292952b1d4b2205a13 Mon Sep 17 00:00:00 2001 From: lxbhahaha <1580622474@qq.com> Date: Fri, 5 Apr 2024 10:51:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=92=8C=E6=9F=A5=E7=9C=8Bcell=E7=9A=84=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/check.py b/check.py index b59acd1..31ec3d7 100644 --- a/check.py +++ b/check.py @@ -13,7 +13,8 @@ END_COLOR = '\033[0m' server_list_path = 'serverList.json' run_realtime = False data_list_lock = threading.Lock() -# data_list = [] +default_cell_width_list = [7, 20, 24, 15] +cell_width_list = [7, 20, 24, 15] table_icon_1 = { 'hline': '─', @@ -235,7 +236,6 @@ def get_table_res(data_list): result_str.extend([time.strftime("%Y%m-%d%H:%M:%S", time.localtime(time.time())), '\n']) # print(time.strftime("%Y%m-%d%H:%M:%S", time.localtime(time.time()))) - cell_width_list = [7, 20, 24, 15] len_last3 = cell_width_list[1] + cell_width_list[2] + cell_width_list[3] + 2 # 输出head ------------------------------------------ result_str.extend([get_line('up', cell_width_list), '\n']) @@ -291,19 +291,33 @@ def get_table_res(data_list): str_list.append(table_icon['vline']) # 占用情况 + # if used_mem < 1000 and util_gpu < 20: + # status = COLOR_GREEN + 'free' + END_COLOR + # text_len = 5 + # elif used_mem / total_mem < 0.5: + # status = COLOR_YELLOW + 'occupied' + END_COLOR + # text_len = 9 + # else: + # status = COLOR_RED + 'occupied' + END_COLOR + # text_len = 9 + # str_list.append(clamp_str(f" {status}", cell_width_list[1]-5, True, 'left', text_len)) + temperature_len = 4 + # 设置文字 if used_mem < 1000 and util_gpu < 20: - status = COLOR_GREEN + 'free' + END_COLOR - text_len = 5 + status = clamp_str(f" free", cell_width_list[1]-temperature_len, True, 'left') + else: + status = clamp_str(f" occupied", cell_width_list[1]-temperature_len, True, 'left') + # 设置颜色 + if used_mem < 1000 and util_gpu < 20: + status = COLOR_GREEN + status + END_COLOR elif used_mem / total_mem < 0.5: - status = COLOR_YELLOW + 'occupied' + END_COLOR - text_len = 9 + status = COLOR_YELLOW + status + END_COLOR else: - status = COLOR_RED + 'occupied' + END_COLOR - text_len = 9 - str_list.append(clamp_str(f" {status}", cell_width_list[1]-5, True, 'left', text_len)) + status = COLOR_RED + status + END_COLOR + str_list.append(status) # 温度 - str_list.append(clamp_str(f"{info['temperature']}C ", 5, True, 'right')) + str_list.append(clamp_str(f"{info['temperature']}C ", temperature_len, True, 'right')) str_list.append(table_icon['vline']) # 显存进度条 @@ -496,6 +510,39 @@ def print_server_list(): print(f"title:{s['title']}") print(f"ip:{s['ip']}, port:{s['port']}, usr:{s['username']}") +def cell_width(args): + global cell_width_list + + if len(args) == 0: + print(f'current cells width: {cell_width_list}') + elif len(args) > 1: + print('参数错误') + return + else: + if args[0] == '-': + print(f'原始值为:{cell_width_list}') + cell_width_list = default_cell_width_list + print(f'恢复默认值为:{cell_width_list}') + else: + widths = args[0].split(',') + if len(widths) != len(cell_width_list): + print('参数长度不正确') + return + temp_target = [] + for i, width in enumerate(widths): + try: + if width == '-': + temp_w = cell_width_list[i] + else: + temp_w = int(width) + temp_target.append(temp_w) + except: + print('宽度值必须为整数或\'-\'') + return + print(f'原始值为:{cell_width_list}') + cell_width_list = temp_target + print(f'修改为:{cell_width_list}') + def main(): # 接受输入 @@ -514,6 +561,8 @@ def main(): realtime(args) elif cmd == 'list': print_server_list() + elif cmd == 'cell-width' or cmd == 'cw': + cell_width(args) elif cmd == 'exit': break elif cmd == 'help': @@ -522,6 +571,7 @@ def main(): print('check, 查看所有显卡状态') print('realtime, 实时显示(rt同)') print('list, 查看文件中记录的所有服务器信息') + print('cell-width, 查看或设置cell的宽度') print('clear, 清空屏幕(cls同)') print('exit, 退出') else: