From c755662870abff537fde90ed078dcbb97ba043e9 Mon Sep 17 00:00:00 2001 From: Denys Duchier Date: Thu, 19 Nov 2015 18:41:52 +0100 Subject: [PATCH 1/2] suppress colorization if stdout is not a tty --- pythonforandroid/toolchain.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 6c0b317a7d..6eca957f77 100755 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -41,7 +41,16 @@ import argparse from appdirs import user_data_dir import sh -from colorama import Style, Fore +if sys.stdout.isatty(): + from colorama import Style, Fore +else: + from collections import defaultdict + class colorama_shim(object): + def __init__(self): + self._dict = defaultdict(str) + def __getattr__(self, key): + return self._dict[key] + Style = Fore = colorama_shim() user_dir = dirname(realpath(os.path.curdir)) toolchain_dir = dirname(__file__) From fbeb6754d89db0f24c61e2b7e11ccb2e7d2d2f72 Mon Sep 17 00:00:00 2001 From: Denys Duchier Date: Thu, 19 Nov 2015 21:12:26 +0100 Subject: [PATCH 2/2] use null logger when stdout is not a tty --- pythonforandroid/toolchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 6eca957f77..f89b93cb70 100755 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -78,7 +78,7 @@ def format(self, record): # handler and reset the level logger.setLevel(logging.INFO) logger.touched = True - ch = logging.StreamHandler(stdout) + ch = logging.StreamHandler(stdout) if sys.stdout.isatty() else logging.NullHandler() formatter = LevelDifferentiatingFormatter('%(message)s') ch.setFormatter(formatter) logger.addHandler(ch)