From 89d00d4a23ce83131f3900235a8c45052fc20b0d Mon Sep 17 00:00:00 2001 From: dimstars Date: Mon, 21 Oct 2024 11:16:37 +0000 Subject: [PATCH] make do_bolt_test compatible with python2 and python3 --- cmake/script/do_bolt_opt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmake/script/do_bolt_opt b/cmake/script/do_bolt_opt index d6a76e9f3..fc15adc0b 100755 --- a/cmake/script/do_bolt_opt +++ b/cmake/script/do_bolt_opt @@ -57,7 +57,15 @@ def shell_run_command(command_str, need_print_all=True, need_print_output=True, close_fds=True) while True: data = ps.stdout.readline() - if data == b'': + if sys.version_info[0] >= 3: + # Python 3 + if isinstance(data, bytes): + data = data.decode('utf-8').strip() + else: + # Python 2 + if isinstance(data, str): + data = data.strip() + if data == '': if ps.poll() is not None: break result["return_message"].append(data) @@ -67,14 +75,14 @@ def shell_run_command(command_str, need_print_all=True, need_print_output=True, if need_print_output and len(data.strip()) > 1: if not is_frist: - print_log("[运行输出]: %s" % data.replace("\n", "")) + print_log("[运行输出]: " + data) is_frist = True else: - data_str = " %s" % data.replace("\n", "") + data_str = " " + data if no_time: print(data_str) else: - print_log(" %s" % data.replace("\n", "")) + print_log(" " + data) result["return_code"] = ps.returncode return result @@ -129,6 +137,7 @@ def main(): ''' # 解析参数 parse_arg() + print_log("python version: " + str(sys.version_info[0])) result = shell_run_command("uname -m", False, False) if len(result["return_message"]) == 0: