From d9edcd93966713c84a6eac7677073738a6f51984 Mon Sep 17 00:00:00 2001 From: Arksine Date: Wed, 3 Mar 2021 09:05:31 -0500 Subject: [PATCH] shell_command: Add "quiet" argument to run_with_response This reduces logging when "run_with_response" is called from a loop or a timer. Signed-off-by: Eric Callahan --- moonraker/plugins/shell_command.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/moonraker/plugins/shell_command.py b/moonraker/plugins/shell_command.py index 1852020..7c88e04 100644 --- a/moonraker/plugins/shell_command.py +++ b/moonraker/plugins/shell_command.py @@ -106,7 +106,7 @@ class ShellCommand: complete = not self.cancelled return self._check_proc_success(complete) - async def run_with_response(self, timeout=2., retries=1): + async def run_with_response(self, timeout=2., retries=1, quiet=False): self.return_code = self.proc = None self.cancelled = False while retries > 0: @@ -123,7 +123,7 @@ class ShellCommand: complete = not self.cancelled if self.log_stderr: logging.info(f"{self.program}: {stderr.decode()}") - if self._check_proc_success(complete): + if self._check_proc_success(complete, quiet): return stdout.decode().rstrip("\n") elif stdout: logging.debug( @@ -154,7 +154,7 @@ class ShellCommand: return False return True - def _check_proc_success(self, complete): + def _check_proc_success(self, complete, quiet=False): self.return_code = self.proc.returncode success = self.return_code == 0 and complete if success: @@ -166,7 +166,8 @@ class ShellCommand: else: msg = f"Command ({self.name}) exited with return code" \ f" {self.return_code}" - logging.info(msg) + if not quiet: + logging.info(msg) return success class ShellCommandFactory: