Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1436321
| From | Andrew Donnellan <andrew.donnellan@au1.ibm.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] checkkconfigsymbols.py: add --no-color option |
| Date | 2016-07-04 10:50 +0200 |
| Message-ID | <rR7JM-3ot-29@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
Add a new option, --no-color, to get rid of ANSI colour escape codes in the
output. Useful if redirecting output to a file or piping to another script.
(It should really be --no-colour, but I'll accept US spelling in the name
of consistency with existing usage in the code comments...)
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
scripts/checkkconfigsymbols.py | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py
index df643f6..a9eba02 100755
--- a/scripts/checkkconfigsymbols.py
+++ b/scripts/checkkconfigsymbols.py
@@ -82,6 +82,10 @@ def parse_options():
default=False,
help="Reset current Git tree even when it's dirty.")
+ parser.add_option('', '--no-color', dest='no_color', action='store_true',
+ default=False,
+ help="Don't print colored output.")
+
(opts, _) = parser.parse_args()
if opts.commit and opts.diff:
@@ -116,6 +120,9 @@ def main():
"""Main function of this module."""
opts = parse_options()
+ global no_color
+ no_color = opts.no_color
+
if opts.sim and not opts.commit and not opts.diff:
sims = find_sims(opts.sim, opts.ignore)
if sims:
@@ -202,14 +209,14 @@ def yel(string):
"""
Color %string yellow.
"""
- return "\033[33m%s\033[0m" % string
+ return string if no_color else "\033[33m%s\033[0m" % string
def red(string):
"""
Color %string red.
"""
- return "\033[31m%s\033[0m" % string
+ return string if no_color else "\033[31m%s\033[0m" % string
def execute(cmd):
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com IBM Australia Limited
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] checkkconfigsymbols.py: add --no-color option Andrew Donnellan <andrew.donnellan@au1.ibm.com> - 2016-07-04 10:50 +0200
Re: [PATCH] checkkconfigsymbols.py: add --no-color option Valentin Rothberg <valentinrothberg@gmail.com> - 2016-07-04 12:50 +0200
Re: checkkconfigsymbols.py: add --no-color option Josh Triplett <josh@joshtriplett.org> - 2016-07-04 14:30 +0200
Re: checkkconfigsymbols.py: add --no-color option Andrew Donnellan <andrew.donnellan@au1.ibm.com> - 2016-07-05 09:30 +0200
[PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY Andrew Donnellan <andrew.donnellan@au1.ibm.com> - 2016-07-05 09:50 +0200
Re: [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY Valentin Rothberg <valentinrothberg@gmail.com> - 2016-07-05 10:50 +0200
csiph-web