Browse Source

Add colored output

Hamilton Turner 11 years ago
parent
commit
024106bf17

+ 13 - 2
toolset/benchmark/benchmarker.py

@@ -18,6 +18,9 @@ import socket
 from multiprocessing import Process
 from datetime import datetime
 
+# Cross-platform colored text
+from colorama import Fore, Back, Style
+
 class Benchmarker:
 
   ##########################################################################################
@@ -793,15 +796,23 @@ class Benchmarker:
   def __finish(self):
     if self.mode == "verify":
       tests = self.__gather_tests
+      print Fore.BLUE
       print header("Verification Summary", top='=', bottom='')
       for test in tests:
         print "| Test: %s" % test.name
         if test.name in self.results['verify'].keys():
           for test_type, result in self.results['verify'][test.name].iteritems():
-            print "|       %s : %s" % (test_type, result)
+            if result.upper() == "PASS":
+              color = Fore.GREEN
+            elif result.upper() == "WARN":
+              color = Fore.YELLOW
+            else:
+              color = Fore.RED
+            print "|       " + test_type.ljust(11) + ' : ' + color + result.upper() + Fore.BLUE
         else:
-          print "|      NO RESULTS (Did framework launch?)"
+          print "|      " + Fore.RED + "NO RESULTS (Did framework launch?)" + Fore.BLUE
       print header('', top='', bottom='=')
+      print Style.RESET_ALL
 
     print "Time to complete: " + str(int(time.time() - self.start_time)) + " seconds"
     print "Results are saved in " + os.path.join(self.result_directory, self.timestamp)

+ 14 - 1
toolset/benchmark/utils.py

@@ -87,4 +87,17 @@ def header(message, top='-', bottom='-'):
     '''
     topheader = (top * 80)[:80]
     bottomheader = (bottom * 80)[:80]
-    return "%s\n  %s\n%s" % (topheader, message, bottomheader)
+    result = ""
+    if topheader != "":
+      result += "%s" % topheader
+    if message != "":
+      if result == "":
+        result = "  %s" % message
+      else:
+        result += "\n  %s" % message
+    if bottomheader != "":
+      if result == "":
+        result = "%s" % bottomheader
+      else:
+        result += "\n%s" % bottomheader
+    return result

+ 4 - 0
toolset/run-tests.py

@@ -10,6 +10,10 @@ from benchmark.benchmarker import Benchmarker
 from setup.linux.unbuffered import Unbuffered
 from setup.linux import setup_util
 
+# Enable cross-platform colored output
+from colorama import init
+init()
+
 ###################################################################################################
 # Main
 ###################################################################################################

+ 3 - 0
toolset/setup/linux/prerequisites.sh

@@ -36,6 +36,9 @@ sudo apt-get -y install \
   libjson0-dev libmcrypt-dev libicu-dev gettext \
   libpq-dev mlton cloc dstat
 
+# For cross-platform colored stdout/stderr messages
+sudo pip install colorama
+
 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
 sudo apt-get -y update
 sudo apt-get install -y gcc-4.8 g++-4.8