diff --git a/common/command.py b/common/command.py index 58886919ec1f9396e7414e89beaa3636281737f3..1d9995fedaceb9bb34232b76d1845dfb80fcf075 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] == '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 @@ -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] == '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)) @@ -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: