[edk2-devel] [PATCH 6/6] BaseTools/PatchCheck: Allow to print colored warnings

Philippe Mathieu-Daudé philmd at redhat.com
Thu Dec 5 16:12:34 UTC 2019


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 at intel.com>
Cc: Liming Gao <liming.gao at intel.com>
Signed-off-by: Philippe Mathieu-Daude <philmd at 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


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#51791): https://edk2.groups.io/g/devel/message/51791
Mute This Topic: https://groups.io/mt/67004111/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list