From 90e0c44310db1bb58b0c6400beb21a5ab7069b45 Mon Sep 17 00:00:00 2001 From: Caohongtao Date: Sun, 7 Apr 2024 03:25:46 +0000 Subject: [PATCH 1/2] update common/command.py. Signed-off-by: Caohongtao --- common/command.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/common/command.py b/common/command.py index 5888691..098a28b 100644 --- a/common/command.py +++ b/common/command.py @@ -21,9 +21,9 @@ class Command: @staticmethod def check_ethtool_cg(cmd_stde): - if cmd_stde == b"Cannot get device coalesce settings: Operation not supported\n": + if cmd_stde == b"Cannot get devices coalesce settings: Operation not supported\n": return True - elif cmd_stde == b"Cannot get device ring settings: Operation not supported\n": + elif cmd_stde == b"Cannot get devices ring settings: Operation not supported\n": return True else: return False @@ -52,8 +52,8 @@ class Command: env_c = os.environ env_c['LANG'] = 'en_US.UTF-8' - check_cmd = cmd.split() - if check_cmd[0] == 'cat' or check_cmd[0] == 'ls': + check_cmd = cmd.split(' ') + if check_cmd[0] == 'cat' or check_cmd[0] == 'ls' or check_cmd[0] == 'cd' : if not os.path.exists(check_cmd[1]): Logger().error("{} does not exist, cmd_run {} unable to execute".format(check_cmd[1], cmd)) return command_result @@ -63,7 +63,7 @@ class Command: if not sys.version_info[0] >= 3: stdout = stdout.replace('\x1b[7l', '') if Command.cmd_check(stdout, stderr, ret.returncode, cmd): - command_result = cmd + '\n'+ stdout.decode('utf8') + command_result = cmd + '\n'+ stdout.decode('utf-8') return command_result @@ -81,8 +81,8 @@ class Command: env_c = os.environ env_c['LANG'] = 'en_US.UTF-8' # 添加文件是否存在判断 - check_cmd = cmd.split() - if check_cmd[0] == 'cat' or check_cmd[0] == 'ls': + check_cmd = cmd.split(' ') + if check_cmd[0] == 'cat' or check_cmd[0] == 'ls' or check_cmd[0] == 'cd': if "scaling_governor" in check_cmd[1] : if len(os.listdir("/sys/devices/system/cpu/cpufreq/")) == 0: Logger().debug("Commmand:{} unable to execute, already in performance mode".format(cmd)) @@ -90,11 +90,10 @@ class Command: elif not os.path.exists(check_cmd[1]): Logger().error("{} does not exist,command: {} unable to execute".format(check_cmd[1], cmd)) return command_result - # ret = subprocess.run(cmd, shell = True, stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env_c) ret = subprocess.Popen(cmd, shell = True, stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env_c) stdout,stderr = ret.communicate() if Command.cmd_check(stdout, stderr, ret.returncode, cmd): - command_result = stdout.decode('utf8') + command_result = stdout.decode('utf-8') return command_result.strip() except Exception as err: @@ -111,11 +110,10 @@ class Command: try: env_c = os.environ env_c['LANG'] = 'en_US.UTF-8' - # ret = subprocess.run(cmd, shell = True, stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env_c) ret = subprocess.Popen(cmd, shell = True, stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env_c) stdout,stderr = ret.communicate() if Command.cmd_check(stdout, stderr, ret.returncode, cmd): - command_result = stderr.decode('utf8') + command_result = stderr.decode('utf-8') return command_result except Exception as err: -- Gitee From f45e96ceaa9f43887f3b9f6d1ad6b75b370f1eee Mon Sep 17 00:00:00 2001 From: Caohongtao Date: Sun, 7 Apr 2024 03:29:31 +0000 Subject: [PATCH 2/2] update common/command.py. Signed-off-by: Caohongtao --- common/command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/command.py b/common/command.py index 098a28b..1d9995f 100644 --- a/common/command.py +++ b/common/command.py @@ -53,7 +53,7 @@ class Command: env_c['LANG'] = 'en_US.UTF-8' check_cmd = cmd.split(' ') - if check_cmd[0] == 'cat' or check_cmd[0] == 'ls' or check_cmd[0] == 'cd' : + if check_cmd[0] == 'cat' or check_cmd[0] == 'ls' or check_cmd[0] == 'll' : if not os.path.exists(check_cmd[1]): Logger().error("{} does not exist, cmd_run {} unable to execute".format(check_cmd[1], cmd)) return command_result @@ -82,7 +82,7 @@ class Command: env_c['LANG'] = 'en_US.UTF-8' # 添加文件是否存在判断 check_cmd = cmd.split(' ') - if check_cmd[0] == 'cat' or check_cmd[0] == 'ls' or check_cmd[0] == 'cd': + if check_cmd[0] == 'cat' or check_cmd[0] == 'ls' or check_cmd[0] == 'll': if "scaling_governor" in check_cmd[1] : if len(os.listdir("/sys/devices/system/cpu/cpufreq/")) == 0: Logger().debug("Commmand:{} unable to execute, already in performance mode".format(cmd)) -- Gitee