From f543b69ee4463df3fb4d4b7c86475562f62e4744 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Mon, 12 Dec 2022 17:25:59 +0100 Subject: [PATCH] feat: error- and debug-output is send to STDERR, instead of STDOUT (#465) Signed-off-by: Jan Kowalleck --- cyclonedx_py/client.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/cyclonedx_py/client.py b/cyclonedx_py/client.py index 4680b9f26..ca4618346 100644 --- a/cyclonedx_py/client.py +++ b/cyclonedx_py/client.py @@ -83,25 +83,25 @@ def get_output(self) -> BaseOutput: try: parser = self._get_input_parser() except CycloneDxCmdNoInputFileSupplied as e: - print(f'ERROR: {str(e)}') + print(f'ERROR: {str(e)}', file=sys.stderr) exit(1) except CycloneDxCmdException as e: - print(f'ERROR: {str(e)}') + print(f'ERROR: {str(e)}', file=sys.stderr) exit(1) if parser and parser.has_warnings(): - print('') - print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') - print('!! Some of your dependencies do not have pinned version !!') - print('!! numbers in your requirements.txt !!') - print('!! !!') - for warning in parser.get_warnings(): - print('!! -> {} !!'.format(warning.get_item().ljust(49))) - print('!! !!') - print('!! The above will NOT be included in the generated !!') - print('!! CycloneDX as version is a mandatory field. !!') - print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') - print('') + print('', + '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!', + '!! Some of your dependencies do not have pinned version !!', + '!! numbers in your requirements.txt !!', + '!! !!', + *('!! -> {} !!'.format(warning.get_item().ljust(49)) for warning in parser.get_warnings()), + '!! !!', + '!! The above will NOT be included in the generated !!', + '!! CycloneDX as version is a mandatory field. !!', + '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!', + '', + sep='\n', file=sys.stderr) bom = Bom.from_parser(parser=parser) @@ -147,7 +147,7 @@ def execute(self) -> None: output = self.get_output() if self._arguments.output_file == '-' or not self._arguments.output_file: self._debug_message('Returning SBOM to STDOUT') - print(output.output_as_string()) + print(output.output_as_string(), file=sys.stdout) return # Check directory writable @@ -242,11 +242,11 @@ def get_arg_parser(*, prog: Optional[str] = None) -> argparse.ArgumentParser: def _debug_message(self, message: str) -> None: if self._DEBUG_ENABLED: - print('[DEBUG] - {} - {}'.format(datetime.now(), message)) + print('[DEBUG] - {} - {}'.format(datetime.now(), message), file=sys.stderr) @staticmethod def _error_and_exit(message: str, exit_code: int = 1) -> None: - print('[ERROR] - {} - {}'.format(datetime.now(), message)) + print('[ERROR] - {} - {}'.format(datetime.now(), message), file=sys.stderr) exit(exit_code) def _get_input_parser(self) -> BaseParser: