Skip to content

Commit

Permalink
improve logging in helper function used by run_shell_cmd to answer qu…
Browse files Browse the repository at this point in the history
…estions for interactive shell commands
  • Loading branch information
boegel committed Aug 16, 2024
1 parent 3e0b4e5 commit e172bcf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def _answer_question(stdout, proc, qa_patterns, qa_wait_patterns):
# replace spaces/line breaks with regex pattern that matches one or more spaces/line breaks,
# and allow extra whitespace at the end
question = space_line_break_pattern.join(space_line_break_regex.split(question)) + r'[\s\n]*$'
_log.debug("Checking for question pattern '{question}'...")
regex = re.compile(question.encode())
res = regex.search(stdout)
if res:
Expand Down Expand Up @@ -284,6 +285,8 @@ def _answer_question(stdout, proc, qa_patterns, qa_wait_patterns):

match_found = True
break
else:
_log.debug(f"No match for question pattern '{question}' at end of stdout: {stdout_end}")
else:
_log.info("No match found for question patterns, considering question wait patterns")
# if no match was found among question patterns,
Expand All @@ -295,14 +298,17 @@ def _answer_question(stdout, proc, qa_patterns, qa_wait_patterns):
# and allow extra whitespace at the end
pattern = space_line_break_pattern.join(space_line_break_regex.split(pattern)) + r'[\s\n]*$'
regex = re.compile(pattern.encode())
log.debug("Checking for question wait pattern '{pattern}'...")
if regex.search(stdout):
_log.info(f"Found match for wait pattern '{pattern}'")
_log.debug(f"Found match for wait pattern '{pattern}' at end of stdout: {stdout_end}")
_log.info(f"Found match for question wait pattern '{pattern}'")
_log.debug(f"Found match for question wait pattern '{pattern}' at end of stdout: {stdout_end}")
match_found = True
break
else:
_log.debug(f"No match for question wait pattern '{pattern}' at end of stdout: {stdout_end}")
else:
_log.info("No match found for question wait patterns")
_log.debug(f"No match found in question/wait patterns at end of stdout: {stdout_end}")
_log.debug(f"No match found in question (wait) patterns at end of stdout: {stdout_end}")

return match_found

Expand Down

0 comments on commit e172bcf

Please sign in to comment.