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 <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-03-03 09:05:31 -05:00
parent 22a5f6720c
commit d9edcd9396
1 changed files with 5 additions and 4 deletions

View File

@ -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,6 +166,7 @@ class ShellCommand:
else:
msg = f"Command ({self.name}) exited with return code" \
f" {self.return_code}"
if not quiet:
logging.info(msg)
return success