From 2f4ebe9dfb2d9854e6ae05834e6062d245dae88d Mon Sep 17 00:00:00 2001 From: Tomas Jelinek Date: Thu, 16 May 2024 10:36:23 +0200 Subject: [PATCH] fix stdout wrapping to terminal width --- CHANGELOG.md | 3 +++ pcs/cli/common/output.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a198d0f7..a6ef6cc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,12 @@ when not specified in `pcs cluster uidgid add` command. Empty options cause corosync start failure. ([ghissue#772]) - Do not allow fencing levels other than 1..9 ([RHEL-2977]) +- Do not wrap pcs output to terminal width if pcs's stdout is redirected + ([RHEL-36514]) [ghissue#772]: https://github.com/ClusterLabs/pcs/issues/772 [RHEL-2977]: https://issues.redhat.com/browse/RHEL-2977 +[RHEL-36514]: https://issues.redhat.com/browse/RHEL-36514 ## [0.11.7] - 2024-01-11 diff --git a/pcs/cli/common/output.py b/pcs/cli/common/output.py index 179f7c03..9dc0e162 100644 --- a/pcs/cli/common/output.py +++ b/pcs/cli/common/output.py @@ -56,9 +56,11 @@ def format_wrap_for_terminal( trim -- number which will be substracted from terminal size. Can be used in cases lines will be indented later by this number of spaces. """ - if (sys.stdout is not None and sys.stdout.isatty()) or ( - sys.stderr is not None and sys.stderr.isatty() - ): + # This function is used for stdout only - we don't care about wrapping + # error messages and debug info. So it checks stdout and not stderr. + # Checking stderr would enable wrapping in case of 'pcs ... | grep ...' + # (stderr is connected to a terminal), which we don't want. (RHEL-36514) + if sys.stdout is not None and sys.stdout.isatty(): return format_wrap( text, # minimal line length is 40 -- 2.25.1