From patchwork Sat Jan 26 00:56:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [bitbake-devel] tinfoil: support other fds, enable color support Date: Sat, 26 Jan 2013 00:56:30 -0000 From: Christopher Larson X-Patchwork-Id: 43449 Message-Id: <1359161790-4482-1-git-send-email-kergoth@gmail.com> To: bitbake-devel@lists.openembedded.org Cc: Christopher Larson From: Christopher Larson 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 --- lib/bb/tinfoil.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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)