summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2020-07-29 11:33:56 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-07-29 11:35:51 +0100
commit4e3240220bf8fc159ba5e797cb6040a3c74db222 (patch)
tree668e134c0ab63f37fa1e77fc026e1b6465ac234b
parentef0ca299d6dd3f6d9bbb8eccb391703806303102 (diff)
downloadpoky-4e3240220bf8fc159ba5e797cb6040a3c74db222.tar.gz
Revert "lib/oe/log_colorizer.py: add LogColorizerProxyProgressHandler"
This reverts commit 312fb3c86a3d84e60867b132666c01859f73ceb2 as this wasn't meant to merge as yet. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oe/log_colorizer.py86
1 files changed, 0 insertions, 86 deletions
diff --git a/meta/lib/oe/log_colorizer.py b/meta/lib/oe/log_colorizer.py
deleted file mode 100644
index 10021ef880..0000000000
--- a/meta/lib/oe/log_colorizer.py
+++ /dev/null
@@ -1,86 +0,0 @@
1# Copyright (C) 2020 Agilent Technologies, Inc.
2# Author: Chris Laplante <chris.laplante@agilent.com>
3#
4# Released under the MIT license (see COPYING.MIT)
5
6from bb.progress import ProgressHandler
7from bb.build import create_progress_handler
8import contextlib
9import re
10import os.path
11
12# from https://stackoverflow.com/a/14693789/221061
13ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
14
15
16class LogColorizerProxyProgressHandler(ProgressHandler):
17 """
18 This is a proxy progress handler. It intercepts log output, stripping any
19 ANSII color escape codes. Then the stripped output is fed to the task's
20 original progress handler which will render the progress bar as usual.
21 """
22 def __init__(self, d, outfile=None, otherargs=None):
23 self._task = d.getVar("BB_RUNTASK")
24 self._color_log = None
25 self._nocolor_log = None
26 self._exit_stack = None
27 self._original_ph = None
28
29 self._suppress_color_output = not not d.getVar("LOG_COLORIZER_SUPPRESS_COLORIZED_OUTPUT")
30
31 self._tempdir = d.getVar("T")
32 logfmt = (d.getVar('BB_LOGFMT') or 'log.{task}.{pid}')
33 self._logbasename = logfmt.format(task=self._task, pid=os.getpid())
34
35 # Setup courtesy symlinks
36 for suffix in [".nocolor", ".color"]:
37 loglink = os.path.join(self._tempdir, 'log.{0}{1}'.format(self._task, suffix))
38 logfn = os.path.join(self._tempdir, self._logbasename + suffix)
39 if loglink:
40 bb.utils.remove(loglink)
41
42 try:
43 os.symlink(self._logbasename + suffix, loglink)
44 except OSError:
45 pass
46
47 super().__init__(d, outfile)
48
49 def __enter__(self):
50 with contextlib.ExitStack() as es:
51 self._color_log = es.enter_context(open(os.path.join(self._tempdir, self._logbasename) + ".color", "w"))
52 self._nocolor_log = es.enter_context(open(os.path.join(self._tempdir, self._logbasename) + ".nocolor", "w"))
53
54 # Reconstitute the original progress handler. We will feed stripped output to it so
55 # that the progress bar still shows up for the task.
56 original_ph = self._data.getVarFlag(self._task, "originalprogress")
57 if original_ph:
58 # We don't want task output showing up on the screen twice, so we'll just have
59 # the original progress handler write to /dev/null.
60 # Note the progress handler itself is responsible for closing the devnull handler.
61 devnull = open("/dev/null", "w")
62 self._original_ph = es.enter_context(create_progress_handler(self._task, original_ph, devnull, self._data))
63
64 self._exit_stack = es.pop_all()
65 super().__enter__()
66
67 def __exit__(self, *exc_info):
68 if self._exit_stack:
69 self._exit_stack.__exit__(*exc_info)
70 super().__exit__(*exc_info)
71
72 def write(self, string):
73 # Filter out ANSI escape sequences using the regular expression
74 filtered = ansi_escape.sub('', string)
75
76 if self._color_log:
77 self._color_log.write(string)
78
79 if self._nocolor_log:
80 self._nocolor_log.write(filtered)
81
82 if self._original_ph:
83 # Pass-through to the original progress handler so we get our progress bar
84 self._original_ph.write(filtered)
85
86 super().write(filtered if self._suppress_color_output else string)