|
|
843f86 |
From 68834a49d9d55bffdc4febeaf23a892011399a63 Mon Sep 17 00:00:00 2001
|
|
|
843f86 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
843f86 |
Date: Wed, 13 Sep 2017 22:03:31 +0200
|
|
|
843f86 |
Subject: [PATCH 3/5] firewall-cmd: Use colors only if output is a TTY
|
|
|
843f86 |
|
|
|
843f86 |
Use isatty() method to check whether output is a TTY or not (e.g.
|
|
|
843f86 |
redirected to a file or pipe) before enclosing error messages in TTY
|
|
|
843f86 |
color escape strings.
|
|
|
843f86 |
|
|
|
843f86 |
While here, simplify things a bit by making print_and_exit() call
|
|
|
843f86 |
print_warning() internally, also adjust commented out code for colored
|
|
|
843f86 |
non-error messages.
|
|
|
843f86 |
|
|
|
843f86 |
Fixes: RHBZ#1368544
|
|
|
843f86 |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
843f86 |
---
|
|
|
843f86 |
src/firewall/command.py | 12 +++++++-----
|
|
|
843f86 |
1 file changed, 7 insertions(+), 5 deletions(-)
|
|
|
843f86 |
|
|
|
843f86 |
diff --git a/src/firewall/command.py b/src/firewall/command.py
|
|
|
843f86 |
index 2dc1c509ae556..50bd4bd0f4103 100644
|
|
|
843f86 |
--- a/src/firewall/command.py
|
|
|
843f86 |
+++ b/src/firewall/command.py
|
|
|
843f86 |
@@ -64,17 +64,19 @@ class FirewallCommand(object):
|
|
|
843f86 |
def print_warning(self, msg=None):
|
|
|
843f86 |
FAIL = '\033[91m'
|
|
|
843f86 |
END = '\033[00m'
|
|
|
843f86 |
- self.print_error_msg(FAIL + msg + END)
|
|
|
843f86 |
+ if sys.stderr.isatty():
|
|
|
843f86 |
+ msg = FAIL + msg + END
|
|
|
843f86 |
+ self.print_error_msg(msg)
|
|
|
843f86 |
|
|
|
843f86 |
def print_and_exit(self, msg=None, exit_code=0):
|
|
|
843f86 |
#OK = '\033[92m'
|
|
|
843f86 |
- FAIL = '\033[91m'
|
|
|
843f86 |
- END = '\033[00m'
|
|
|
843f86 |
+ #END = '\033[00m'
|
|
|
843f86 |
if exit_code > 1:
|
|
|
843f86 |
- self.print_error_msg(FAIL + msg + END)
|
|
|
843f86 |
+ self.print_warning(msg)
|
|
|
843f86 |
else:
|
|
|
843f86 |
+ #if sys.stdout.isatty():
|
|
|
843f86 |
+ # msg = OK + msg + END
|
|
|
843f86 |
self.print_msg(msg)
|
|
|
843f86 |
- #self.print_msg(OK + msg + END)
|
|
|
843f86 |
sys.exit(exit_code)
|
|
|
843f86 |
|
|
|
843f86 |
def fail(self, msg=None):
|
|
|
843f86 |
--
|
|
|
843f86 |
2.13.1
|
|
|
843f86 |
|