From: Michael Tremer Date: Tue, 25 Oct 2022 09:17:31 +0000 (+0000) Subject: backend: command: Add option to return output X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ff7f6a39f396d0ea1c8cae3018a8b579d9066a1;p=pbs.git backend: command: Add option to return output Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index 52d01aa2..d570e263 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -177,10 +177,12 @@ class Backend(object): # Commands - async def command(self, *args, krb5_auth=False, **kwargs): + async def command(self, *args, krb5_auth=False, return_output=False, **kwargs): """ Runs this shell command """ + stdout = [] + # Authenticate using Kerberos if krb5_auth: await self.krb5_auth() @@ -208,11 +210,19 @@ class Backend(object): # Strip newline line = line.rstrip() - log.info(line) + # Log the output + log.debug(line) + + # Store the output if requested + if return_output: + stdout.append(line) # Wait until the process has finished await process.wait() + if return_output: + return "\n".join(stdout) + async def krb5_auth(self): log.debug("Performing Kerberos authentication...")