aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkkconfigsymbols.py
diff options
context:
space:
mode:
authorAndrew Donnellan <andrew.donnellan@au1.ibm.com>2016-07-05 03:47:37 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-08-18 12:12:07 -0400
commit4c73c0882b34d0383ff417e2d66c127f848cfe06 (patch)
tree112cecea165537e4112c428647f20f6e4f8c2068 /scripts/checkkconfigsymbols.py
parent694d0d0bb2030d2e36df73e2d23d5770511dbc8d (diff)
checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY
Only print the ANSI colour escape codes if stdout is a TTY. Useful if redirecting output to a file or piping to another script. Also add a new option, --no-color, if the user wants to disable colour output for whatever reason. Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Acked-by: Valentin Rothberg <valentinrothberg@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'scripts/checkkconfigsymbols.py')
-rwxr-xr-xscripts/checkkconfigsymbols.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py
index df643f60bb41..b140fc9018b1 100755
--- a/scripts/checkkconfigsymbols.py
+++ b/scripts/checkkconfigsymbols.py
@@ -82,6 +82,11 @@ def parse_options():
82 default=False, 82 default=False,
83 help="Reset current Git tree even when it's dirty.") 83 help="Reset current Git tree even when it's dirty.")
84 84
85 parser.add_option('', '--no-color', dest='color', action='store_false',
86 default=True,
87 help="Don't print colored output. Default when not "
88 "outputting to a terminal.")
89
85 (opts, _) = parser.parse_args() 90 (opts, _) = parser.parse_args()
86 91
87 if opts.commit and opts.diff: 92 if opts.commit and opts.diff:
@@ -116,6 +121,9 @@ def main():
116 """Main function of this module.""" 121 """Main function of this module."""
117 opts = parse_options() 122 opts = parse_options()
118 123
124 global color
125 color = opts.color and sys.stdout.isatty()
126
119 if opts.sim and not opts.commit and not opts.diff: 127 if opts.sim and not opts.commit and not opts.diff:
120 sims = find_sims(opts.sim, opts.ignore) 128 sims = find_sims(opts.sim, opts.ignore)
121 if sims: 129 if sims:
@@ -202,14 +210,14 @@ def yel(string):
202 """ 210 """
203 Color %string yellow. 211 Color %string yellow.
204 """ 212 """
205 return "\033[33m%s\033[0m" % string 213 return "\033[33m%s\033[0m" % string if color else string
206 214
207 215
208def red(string): 216def red(string):
209 """ 217 """
210 Color %string red. 218 Color %string red.
211 """ 219 """
212 return "\033[31m%s\033[0m" % string 220 return "\033[31m%s\033[0m" % string if color else string
213 221
214 222
215def execute(cmd): 223def execute(cmd):