From da63824b885b9eda4a39bad1a648fd1ef18f5301 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Fri, 9 Apr 2021 15:54:54 +0200 Subject: [PATCH] Fix grep_files when some file doesn't match given pattern Change-Id: Iff8f29d3a083398e5cd4ec5595fc6d7dc39894fe --- tobiko/shell/grep.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tobiko/shell/grep.py b/tobiko/shell/grep.py index 6710316f7..30f26ba85 100644 --- a/tobiko/shell/grep.py +++ b/tobiko/shell/grep.py @@ -48,23 +48,26 @@ def grep(pattern: str, raise ValueError("command and files can't be both empty or None") try: - result = sh.execute(command_line, + stdout = sh.execute(command_line, ssh_client=ssh_client, - **execute_params) + **execute_params).stdout except sh.ShellCommandFailed as ex: if ex.exit_status > 1: # Some unknown problem occurred raise - else: - output_lines: typing.List[str] = [ - line - for line in result.stdout.splitlines() - if blank_lines or line.strip()] - if output_lines: - return output_lines + stdout = ex.stdout + + output_lines: typing.List[str] = [ + line + for line in stdout.splitlines() + if blank_lines or line.strip()] + if output_lines: + return output_lines + + login = ssh_client.login if ssh_client else None raise NoMatchingLinesFound(pattern=pattern, files=files, - login=ssh_client and ssh_client.login or None) + login=login) def grep_files(pattern: str,