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:
parent
22a5f6720c
commit
d9edcd9396
|
@ -106,7 +106,7 @@ class ShellCommand:
|
||||||
complete = not self.cancelled
|
complete = not self.cancelled
|
||||||
return self._check_proc_success(complete)
|
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.return_code = self.proc = None
|
||||||
self.cancelled = False
|
self.cancelled = False
|
||||||
while retries > 0:
|
while retries > 0:
|
||||||
|
@ -123,7 +123,7 @@ class ShellCommand:
|
||||||
complete = not self.cancelled
|
complete = not self.cancelled
|
||||||
if self.log_stderr:
|
if self.log_stderr:
|
||||||
logging.info(f"{self.program}: {stderr.decode()}")
|
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")
|
return stdout.decode().rstrip("\n")
|
||||||
elif stdout:
|
elif stdout:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
|
@ -154,7 +154,7 @@ class ShellCommand:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _check_proc_success(self, complete):
|
def _check_proc_success(self, complete, quiet=False):
|
||||||
self.return_code = self.proc.returncode
|
self.return_code = self.proc.returncode
|
||||||
success = self.return_code == 0 and complete
|
success = self.return_code == 0 and complete
|
||||||
if success:
|
if success:
|
||||||
|
@ -166,7 +166,8 @@ class ShellCommand:
|
||||||
else:
|
else:
|
||||||
msg = f"Command ({self.name}) exited with return code" \
|
msg = f"Command ({self.name}) exited with return code" \
|
||||||
f" {self.return_code}"
|
f" {self.return_code}"
|
||||||
logging.info(msg)
|
if not quiet:
|
||||||
|
logging.info(msg)
|
||||||
return success
|
return success
|
||||||
|
|
||||||
class ShellCommandFactory:
|
class ShellCommandFactory:
|
||||||
|
|
Loading…
Reference in New Issue