linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkkconfigsymbols.py: add --no-color option
@ 2016-07-04  8:39 Andrew Donnellan
  2016-07-04 10:44 ` Valentin Rothberg
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Andrew Donnellan @ 2016-07-04  8:39 UTC (permalink / raw)
  To: linux-kernel, gregkh, valentinrothberg

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] checkkconfigsymbols.py: add --no-color option
  2016-07-04  8:39 [PATCH] checkkconfigsymbols.py: add --no-color option Andrew Donnellan
@ 2016-07-04 10:44 ` Valentin Rothberg
  2016-07-04 12:24 ` Josh Triplett
  2016-07-05  7:47 ` [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY Andrew Donnellan
  2 siblings, 0 replies; 8+ messages in thread
From: Valentin Rothberg @ 2016-07-04 10:44 UTC (permalink / raw)
  To: Andrew Donnellan; +Cc: linux-kernel, gregkh

Hi Andrew,

thanks for your patch.  Please remove the colour comment from the commit
message and resend the patch.  Such comments are better below the '---'.

On Jul 04 '16 18:39, Andrew Donnellan wrote:
> 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>

Acked-by: Valentin Rothberg <valentinrothberg@gmail.com>

Thanks,
 Valentin
> ---
>  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
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: checkkconfigsymbols.py: add --no-color option
  2016-07-04  8:39 [PATCH] checkkconfigsymbols.py: add --no-color option Andrew Donnellan
  2016-07-04 10:44 ` Valentin Rothberg
@ 2016-07-04 12:24 ` Josh Triplett
  2016-07-05  7:22   ` Andrew Donnellan
  2016-07-05  7:47 ` [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY Andrew Donnellan
  2 siblings, 1 reply; 8+ messages in thread
From: Josh Triplett @ 2016-07-04 12:24 UTC (permalink / raw)
  To: Andrew Donnellan; +Cc: linux-kernel, gregkh, valentinrothberg

On Mon, Jul 04, 2016 at 06:39:30PM +1000, Andrew Donnellan wrote:
> 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>
> Acked-by: Valentin Rothberg <valentinrothberg@gmail.com>

Rather than requiring an explicit option, how about detecting
whether stdout is a TTY and automatically suppressing color?
You could check "os.isatty(1)" in main(), and set a global "color =
False".  That would automatically handle the cases of redirecting to a
file or piping to another script, without requiring the user to pass
--no-color.

- Josh Triplett

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: checkkconfigsymbols.py: add --no-color option
  2016-07-04 12:24 ` Josh Triplett
@ 2016-07-05  7:22   ` Andrew Donnellan
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Donnellan @ 2016-07-05  7:22 UTC (permalink / raw)
  To: Josh Triplett; +Cc: linux-kernel, gregkh, valentinrothberg

On 04/07/16 22:24, Josh Triplett wrote:
> Rather than requiring an explicit option, how about detecting
> whether stdout is a TTY and automatically suppressing color?
> You could check "os.isatty(1)" in main(), and set a global "color =
> False".  That would automatically handle the cases of redirecting to a
> file or piping to another script, without requiring the user to pass
> --no-color.

That's a good point - I'll submit a v2 with that.

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY
  2016-07-04  8:39 [PATCH] checkkconfigsymbols.py: add --no-color option Andrew Donnellan
  2016-07-04 10:44 ` Valentin Rothberg
  2016-07-04 12:24 ` Josh Triplett
@ 2016-07-05  7:47 ` Andrew Donnellan
  2016-07-05  8:45   ` Valentin Rothberg
  2016-08-16  8:25   ` Valentin Rothberg
  2 siblings, 2 replies; 8+ messages in thread
From: Andrew Donnellan @ 2016-07-05  7:47 UTC (permalink / raw)
  To: linux-kernel, gregkh, valentinrothberg, josh

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>

---

V1->V2:
	- automatically detect non-TTYs and disable colour output.
	  Suggested by Josh Triplett
---
 scripts/checkkconfigsymbols.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py
index df643f6..b140fc9 100755
--- a/scripts/checkkconfigsymbols.py
+++ b/scripts/checkkconfigsymbols.py
@@ -82,6 +82,11 @@ def parse_options():
                       default=False,
                       help="Reset current Git tree even when it's dirty.")
 
+    parser.add_option('', '--no-color', dest='color', action='store_false',
+                      default=True,
+                      help="Don't print colored output. Default when not "
+                           "outputting to a terminal.")
+
     (opts, _) = parser.parse_args()
 
     if opts.commit and opts.diff:
@@ -116,6 +121,9 @@ def main():
     """Main function of this module."""
     opts = parse_options()
 
+    global color
+    color = opts.color and sys.stdout.isatty()
+
     if opts.sim and not opts.commit and not opts.diff:
         sims = find_sims(opts.sim, opts.ignore)
         if sims:
@@ -202,14 +210,14 @@ def yel(string):
     """
     Color %string yellow.
     """
-    return "\033[33m%s\033[0m" % string
+    return "\033[33m%s\033[0m" % string if color else string
 
 
 def red(string):
     """
     Color %string red.
     """
-    return "\033[31m%s\033[0m" % string
+    return "\033[31m%s\033[0m" % string if color else string
 
 
 def execute(cmd):
-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY
  2016-07-05  7:47 ` [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY Andrew Donnellan
@ 2016-07-05  8:45   ` Valentin Rothberg
  2016-08-16  8:25   ` Valentin Rothberg
  1 sibling, 0 replies; 8+ messages in thread
From: Valentin Rothberg @ 2016-07-05  8:45 UTC (permalink / raw)
  To: Andrew Donnellan; +Cc: LKML, Greg Kroah-Hartman, josh

Hi Andrew,

I am fine with this version of the patch, thanks.  Usually patches to
this script go through Greg's misc tree.

Best regards,
 Valentin

On Tue, Jul 5, 2016 at 9:47 AM, Andrew Donnellan
<andrew.donnellan@au1.ibm.com> wrote:
> 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>
>
> ---
>
> V1->V2:
>         - automatically detect non-TTYs and disable colour output.
>           Suggested by Josh Triplett
> ---
>  scripts/checkkconfigsymbols.py | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py
> index df643f6..b140fc9 100755
> --- a/scripts/checkkconfigsymbols.py
> +++ b/scripts/checkkconfigsymbols.py
> @@ -82,6 +82,11 @@ def parse_options():
>                        default=False,
>                        help="Reset current Git tree even when it's dirty.")
>
> +    parser.add_option('', '--no-color', dest='color', action='store_false',
> +                      default=True,
> +                      help="Don't print colored output. Default when not "
> +                           "outputting to a terminal.")
> +
>      (opts, _) = parser.parse_args()
>
>      if opts.commit and opts.diff:
> @@ -116,6 +121,9 @@ def main():
>      """Main function of this module."""
>      opts = parse_options()
>
> +    global color
> +    color = opts.color and sys.stdout.isatty()
> +
>      if opts.sim and not opts.commit and not opts.diff:
>          sims = find_sims(opts.sim, opts.ignore)
>          if sims:
> @@ -202,14 +210,14 @@ def yel(string):
>      """
>      Color %string yellow.
>      """
> -    return "\033[33m%s\033[0m" % string
> +    return "\033[33m%s\033[0m" % string if color else string
>
>
>  def red(string):
>      """
>      Color %string red.
>      """
> -    return "\033[31m%s\033[0m" % string
> +    return "\033[31m%s\033[0m" % string if color else string
>
>
>  def execute(cmd):
> --
> Andrew Donnellan              OzLabs, ADL Canberra
> andrew.donnellan@au1.ibm.com  IBM Australia Limited
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY
  2016-07-05  7:47 ` [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY Andrew Donnellan
  2016-07-05  8:45   ` Valentin Rothberg
@ 2016-08-16  8:25   ` Valentin Rothberg
  2016-08-16 10:49     ` Greg Kroah-Hartman
  1 sibling, 1 reply; 8+ messages in thread
From: Valentin Rothberg @ 2016-08-16  8:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Andrew Donnellan; +Cc: LKML, josh

Hi Greg,

could you pick up this patch?

On Tue, Jul 5, 2016 at 9:47 AM, Andrew Donnellan
<andrew.donnellan@au1.ibm.com> wrote:
> 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>

> ---
>
> V1->V2:
>         - automatically detect non-TTYs and disable colour output.
>           Suggested by Josh Triplett
> ---
>  scripts/checkkconfigsymbols.py | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py
> index df643f6..b140fc9 100755
> --- a/scripts/checkkconfigsymbols.py
> +++ b/scripts/checkkconfigsymbols.py
> @@ -82,6 +82,11 @@ def parse_options():
>                        default=False,
>                        help="Reset current Git tree even when it's dirty.")
>
> +    parser.add_option('', '--no-color', dest='color', action='store_false',
> +                      default=True,
> +                      help="Don't print colored output. Default when not "
> +                           "outputting to a terminal.")
> +
>      (opts, _) = parser.parse_args()
>
>      if opts.commit and opts.diff:
> @@ -116,6 +121,9 @@ def main():
>      """Main function of this module."""
>      opts = parse_options()
>
> +    global color
> +    color = opts.color and sys.stdout.isatty()
> +
>      if opts.sim and not opts.commit and not opts.diff:
>          sims = find_sims(opts.sim, opts.ignore)
>          if sims:
> @@ -202,14 +210,14 @@ def yel(string):
>      """
>      Color %string yellow.
>      """
> -    return "\033[33m%s\033[0m" % string
> +    return "\033[33m%s\033[0m" % string if color else string
>
>
>  def red(string):
>      """
>      Color %string red.
>      """
> -    return "\033[31m%s\033[0m" % string
> +    return "\033[31m%s\033[0m" % string if color else string
>
>
>  def execute(cmd):
> --
> Andrew Donnellan              OzLabs, ADL Canberra
> andrew.donnellan@au1.ibm.com  IBM Australia Limited
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY
  2016-08-16  8:25   ` Valentin Rothberg
@ 2016-08-16 10:49     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2016-08-16 10:49 UTC (permalink / raw)
  To: Valentin Rothberg; +Cc: Andrew Donnellan, LKML, josh

On Tue, Aug 16, 2016 at 10:25:48AM +0200, Valentin Rothberg wrote:
> Hi Greg,
> 
> could you pick up this patch?
> 
> On Tue, Jul 5, 2016 at 9:47 AM, Andrew Donnellan
> <andrew.donnellan@au1.ibm.com> wrote:
> > 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>

It's in my very long "to-review" queue, it's not lost, just seems like
it...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-08-16 10:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-04  8:39 [PATCH] checkkconfigsymbols.py: add --no-color option Andrew Donnellan
2016-07-04 10:44 ` Valentin Rothberg
2016-07-04 12:24 ` Josh Triplett
2016-07-05  7:22   ` Andrew Donnellan
2016-07-05  7:47 ` [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY Andrew Donnellan
2016-07-05  8:45   ` Valentin Rothberg
2016-08-16  8:25   ` Valentin Rothberg
2016-08-16 10:49     ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).