public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: devel@edk2.groups.io
Cc: Philippe Mathieu-Daude <philmd@redhat.com>,
	Bob Feng <bob.c.feng@intel.com>,
	Liming Gao <liming.gao@intel.com>
Subject: [PATCH 6/6] BaseTools/PatchCheck: Allow to print colored warnings
Date: Thu,  5 Dec 2019 17:12:34 +0100	[thread overview]
Message-ID: <20191205161234.25071-7-philmd@redhat.com> (raw)
In-Reply-To: <20191205161234.25071-1-philmd@redhat.com>

If the user has the termcolor package installed, and he configured
a 'color.checkpatch.error' color, use it to display colored warnings.

Example to display warnings in red:

  $ git config color.checkpatch.error red

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Philippe Mathieu-Daude <philmd@redhat.com>
---
 BaseTools/Scripts/PatchCheck.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py
index 5692f6eaf8bd..8e37311bd69a 100755
--- a/BaseTools/Scripts/PatchCheck.py
+++ b/BaseTools/Scripts/PatchCheck.py
@@ -32,6 +32,19 @@ def printw(line):
     """Print a warning to the console."""
     print(line)
 
+if run_git('config', 'color.ui') != 'false':
+    # If the user configure git color.checkpatch.error and the termcolor package
+    # is available, display warnings using the requested color.
+    warning_color = run_git('config', 'color.checkpatch.error')
+    if warning_color:
+        try:
+            from termcolor import colored, cprint
+            _ = colored("check we can parse the color", warning_color.strip())
+            def printw(line):
+                cprint(line, color=warning_color.strip(), attrs=['bold'])
+        except:
+            pass
+
 class Verbose:
     SILENT, QUIET, ONELINE, NORMAL = range(4)
     level = NORMAL
-- 
2.21.0


      parent reply	other threads:[~2019-12-05 16:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05 16:12 [PATCH 0/6] BaseTools: Improve PatchCheck and add GitPostCommitHook Philippe Mathieu-Daudé
2019-12-05 16:12 ` [PATCH 1/6] BaseTools/PatchCheck: Stop parsing commit message after --- separator Philippe Mathieu-Daudé
2019-12-05 19:02   ` Laszlo Ersek
2019-12-05 16:12 ` [PATCH 2/6] BaseTools/PatchCheck: Add a --quiet option Philippe Mathieu-Daudé
2019-12-05 16:12 ` [PATCH 3/6] BaseTools/Scripts: Add GitPostCommitHook.py Philippe Mathieu-Daudé
2019-12-05 19:24   ` Laszlo Ersek
2019-12-05 16:12 ` [PATCH 4/6] BaseTools/PatchCheck: Extract the run_git() function Philippe Mathieu-Daudé
2019-12-05 16:12 ` [PATCH 5/6] BaseTools/PatchCheck: Add printw() function to print warnings Philippe Mathieu-Daudé
2019-12-05 16:12 ` Philippe Mathieu-Daudé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191205161234.25071-7-philmd@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox