From f2f0f51d163b75926bd16d658a230247ccafeb8a Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 10 Feb 2015 23:38:01 +0000 Subject: [PATCH] Added colorama to toolchain notification function and basic test suite prompts --- workspace_tools/test_api.py | 10 +++++++--- workspace_tools/toolchains/__init__.py | 22 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/workspace_tools/test_api.py b/workspace_tools/test_api.py index 98905239a5..e88c729e02 100644 --- a/workspace_tools/test_api.py +++ b/workspace_tools/test_api.py @@ -28,6 +28,7 @@ import optparse import datetime import threading from types import ListType +from colorama import Fore, Back, Style from prettytable import PrettyTable from time import sleep, time @@ -172,6 +173,9 @@ class SingleTestRunner(object): _opts_extend_test_timeout=None): """ Let's try hard to init this object """ + from colorama import init + init() + PATTERN = "\\{(" + "|".join(self.TEST_RESULT_MAPPING.keys()) + ")\\}" self.RE_DETECT_TESTCASE_RESULT = re.compile(PATTERN) # Settings related to test loops counters @@ -759,7 +763,7 @@ class SingleTestRunner(object): separator = "::" time_info = " in %.2f of %d sec" % (round(elapsed_time, 2), duration) result = separator.join(tokens) + " [" + test_result +"]" + time_info - return result + return Fore.MAGENTA + result + Fore.RESET def shape_test_loop_ok_result_count(self, test_all_result): """ Reformats list of results to simple string @@ -842,7 +846,7 @@ class SingleTestRunner(object): cmd += ["-R", str(reset_tout)] if verbose: - print "Executing '" + " ".join(cmd) + "'" + print Fore.MAGENTA + "Executing '" + " ".join(cmd) + "'" + Fore.RESET print "Test::Output::Start" proc = Popen(cmd, stdout=PIPE, cwd=HOST_TESTS) @@ -851,7 +855,7 @@ class SingleTestRunner(object): line = '' output = [] start_time = time() - while (time() - start_time) < (duration + 5): # Extra 5 seconds for flashing + while (time() - start_time) < (duration): c = get_char_from_queue(obs) if c: if verbose: diff --git a/workspace_tools/toolchains/__init__.py b/workspace_tools/toolchains/__init__.py index dd1a02a72d..b42b2f5317 100644 --- a/workspace_tools/toolchains/__init__.py +++ b/workspace_tools/toolchains/__init__.py @@ -17,6 +17,7 @@ limitations under the License. import re import sys +import colorama from os import stat, walk from copy import copy from time import time, sleep @@ -49,6 +50,23 @@ def print_notify(event, silent=False): if not silent: print '%s: %s' % (event['action'].title(), basename(event['file'])) +def print_notify_color(event, silent=False): + """ Default command line notification with colors + """ + from colorama import Fore, Back, Style + + if event['type'] in ['info', 'debug']: + print Fore.GREEN + event['message'] + Fore.RESET + + elif event['type'] == 'cc': + event['severity'] = event['severity'].title() + event['file'] = basename(event['file']) + print Fore.YELLOW + '[%(severity)s] %(file)s@%(line)s: %(message)s'% event + Fore.RESET + + elif event['type'] == 'progress': + if not silent: + print '%s: %s' % (event['action'].title(), basename(event['file'])) + def print_notify_verbose(event, silent=False): """ Default command line notification with more verbose mode """ @@ -215,7 +233,7 @@ class mbedToolchain: self.legacy_ignore_dirs = LEGACY_IGNORE_DIRS - set([target.name, LEGACY_TOOLCHAIN_NAMES[self.name]]) - self.notify_fun = notify if notify is not None else print_notify + self.notify_fun = notify if notify is not None else print_notify_color self.options = options if options is not None else [] self.macros = macros or [] @@ -704,6 +722,8 @@ class mbedToolchain: def var(self, key, value): self.notify({'type': 'var', 'key': key, 'val': value}) +from colorama import init +init() from workspace_tools.settings import ARM_BIN from workspace_tools.settings import GCC_ARM_PATH, GCC_CR_PATH, GCC_CS_PATH, CW_EWL_PATH, CW_GCC_PATH