Skip to content

Commit

Permalink
EdkRepo: Removing behavior that causes exception storm
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kevinsun49 committed Mar 17, 2022
1 parent 5aa61f7 commit b6693a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 6 additions & 6 deletions edkrepo/commands/log_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))

Expand All @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions edkrepo/common/ui_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## @file
# ui_functions.py
#
# Copyright (c) 2017- 2021, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b6693a7

Please sign in to comment.