Patchwork tinfoil: support other fds, enable color support

login
register
mail settings
Submitter Christopher Larson
Date Jan. 26, 2013, 12:55 a.m.
Message ID <1359161744-4193-1-git-send-email-kergoth@gmail.com>
Download mbox | patch
Permalink /patch/43447/
State New
Headers show

Comments

Christopher Larson - Jan. 26, 2013, 12:55 a.m.
From: Christopher Larson <chris_larson@mentor.com>

Rather than only handling sys.stdout, also support any arbitrary file object,
and enable color for the formatter if that file is a tty.

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
---
 lib/bb/tinfoil.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Christopher Larson - Jan. 26, 2013, 12:57 a.m.
On Fri, Jan 25, 2013 at 5:55 PM, Christopher Larson <kergoth@gmail.com>wrote:

> From: Christopher Larson <chris_larson@mentor.com>
>
> Rather than only handling sys.stdout, also support any arbitrary file
> object,
> and enable color for the formatter if that file is a tty.
>
> Signed-off-by: Christopher Larson <chris_larson@mentor.com>
>

Erm, ignore this, wrong list. I fail at navigating my shell history today,
apparently

Patch

diff --git a/lib/bb/tinfoil.py b/lib/bb/tinfoil.py
index 73d8fe9..cb53f3e 100644
--- a/lib/bb/tinfoil.py
+++ b/lib/bb/tinfoil.py
@@ -29,15 +29,17 @@  from bb.cooker import state
 import bb.fetch2
 
 class Tinfoil:
-    def __init__(self):
+    def __init__(self, output=sys.stdout):
         # Needed to avoid deprecation warnings with python 2.6
         warnings.filterwarnings("ignore", category=DeprecationWarning)
 
         # Set up logging
         self.logger = logging.getLogger('BitBake')
-        console = logging.StreamHandler(sys.stdout)
-        format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
+        console = logging.StreamHandler(output)
         bb.msg.addDefaultlogFilter(console)
+        format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
+        if output.isatty():
+            format.enable_color()
         console.setFormatter(format)
         self.logger.addHandler(console)