From b6693a718761cd35719ecc24ec1fff4036d529eb Mon Sep 17 00:00:00 2001 From: Kevin Sun Date: Thu, 17 Mar 2022 16:05:42 -0700 Subject: [PATCH] EdkRepo: Removing behavior that causes exception storm Refactoring to avoid known colorama behavior that would cause an exponentially increasing amount of recursive calls resulting in an exception storm. Signed-off-by: Kevin Sun --- edkrepo/commands/log_command.py | 12 ++++++------ edkrepo/common/ui_functions.py | 11 ++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/edkrepo/commands/log_command.py b/edkrepo/commands/log_command.py index f101ec3..aee7d60 100644 --- a/edkrepo/commands/log_command.py +++ b/edkrepo/commands/log_command.py @@ -18,7 +18,7 @@ from edkrepo.commands.edkrepo_command import EdkrepoCommand import edkrepo.commands.arguments.log_args as arguments from edkrepo.common.common_repo_functions import sort_commits, find_less -from edkrepo.common.ui_functions import print_safe, safe_str +import edkrepo.common.ui_functions as ui_functions from edkrepo.config.config_factory import get_workspace_path, get_workspace_manifest class LogCommand(EdkrepoCommand): @@ -70,7 +70,7 @@ def run_command(self, args, config): Fore.CYAN, os.path.basename(commit.repo.working_dir), Fore.RESET, - safe_str(commit.summary)) + ui_functions.safe_str(commit.summary)) if use_less: output_string = separator.join((output_string, oneline)) @@ -88,20 +88,20 @@ def run_command(self, args, config): author_string = "Author: {} <{}>".format(commit.author.name, commit.author.email) date_string = "Date: {} {}".format(time_string, time_zone_string) if use_less: - output_string = separator.join((output_string, hexsha_string, safe_str(author_string), date_string)) + output_string = separator.join((output_string, hexsha_string, ui_functions.safe_str(author_string), date_string)) commit_string = "" for line in commit.message.splitlines(): - commit_string = separator.join((commit_string, safe_str(" {}".format(line)))) + commit_string = separator.join((commit_string, ui_functions.safe_str(" {}".format(line)))) output_string = separator.join((output_string, commit_string, separator)) else: print(hexsha_string) - print_safe(author_string) + ui_functions.print_safe(author_string) print(date_string) print("") for line in commit.message.splitlines(): - print_safe(" {}".format(line)) + ui_functions.print_safe(" {}".format(line)) print("") if less_path: less_output = subprocess.Popen([str(less_path), '-F', '-R', '-S', '-X', '-K'], stdin=subprocess.PIPE, stdout=sys.stdout, universal_newlines=True) diff --git a/edkrepo/common/ui_functions.py b/edkrepo/common/ui_functions.py index 90771af..ccf4d58 100644 --- a/edkrepo/common/ui_functions.py +++ b/edkrepo/common/ui_functions.py @@ -3,7 +3,7 @@ ## @file # ui_functions.py # -# Copyright (c) 2017- 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -51,33 +51,30 @@ def display_git_output(output_data, verbose=False): if verbose and output_data[2]: print_info_msg(output_data[2]) -def print_info_msg(info_msg, header=True, force_color_output=None): +def print_info_msg(info_msg, header=True): """ Displays informational message with (default) or without header. """ - init_color_console(force_color_output) if header: info_msg_formatted = "Info: {}".format(info_msg) else: info_msg_formatted = "{}".format(info_msg) print(info_msg_formatted) -def print_warning_msg(warning_msg, header=True, force_color_output=None): +def print_warning_msg(warning_msg, header=True): """ Displays warning message with (default) or without header. """ - init_color_console(force_color_output) if header: warning_msg_formatted = "{}{}Warning: {}{}{}".format(Style.BRIGHT, Fore.YELLOW, Style.RESET_ALL, Fore.YELLOW, warning_msg) else: warning_msg_formatted = "{}{}".format(Fore.YELLOW, warning_msg) print(warning_msg_formatted) -def print_error_msg(error_msg, header=True, force_color_output=None): +def print_error_msg(error_msg, header=True): """ Displays error message with (default) or without header. """ - init_color_console(force_color_output) if header: error_msg_formatted = "{}{}Error: {}{}{}".format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED, error_msg) else: