summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorChris Laplante <chris.laplante@agilent.com>2020-07-31 11:42:48 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-08-08 09:19:34 +0100
commit5a80602564539cf0fdbabde8095969efa6077045 (patch)
tree7e6054ac377f88d1899cc8a1f92a1f747f9829a2 /bitbake/lib
parent9b41300d47301121517b811e29806c9c2efa18b2 (diff)
downloadpoky-5a80602564539cf0fdbabde8095969efa6077045.tar.gz
bitbake: progress: filter ANSI escape codes before looking for progress text
This is in prepartion for introducing the log-colorizer bbclass into poky. (Bitbake rev: 889a873d71a6543efb71a0eb4ea6632c9f17175d) Signed-off-by: Chris Laplante <chris.laplante@agilent.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/progress.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/bitbake/lib/bb/progress.py b/bitbake/lib/bb/progress.py
index 8cddefaebe..d051ba0198 100644
--- a/bitbake/lib/bb/progress.py
+++ b/bitbake/lib/bb/progress.py
@@ -15,6 +15,25 @@ import bb.build
15from bb.build import StdoutNoopContextManager 15from bb.build import StdoutNoopContextManager
16 16
17 17
18# from https://stackoverflow.com/a/14693789/221061
19ANSI_ESCAPE_REGEX = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
20
21
22def filter_color(string):
23 """
24 Filter ANSI escape codes out of |string|, return new string
25 """
26 return ANSI_ESCAPE_REGEX.sub('', string)
27
28
29def filter_color_n(string):
30 """
31 Filter ANSI escape codes out of |string|, returns tuple of
32 (new string, # of ANSI codes removed)
33 """
34 return ANSI_ESCAPE_REGEX.subn('', string)
35
36
18class ProgressHandler: 37class ProgressHandler:
19 """ 38 """
20 Base class that can pretend to be a file object well enough to be 39 Base class that can pretend to be a file object well enough to be
@@ -82,7 +101,7 @@ class LineFilterProgressHandler(ProgressHandler):
82 lbreakpos = line.rfind('\r') + 1 101 lbreakpos = line.rfind('\r') + 1
83 if lbreakpos: 102 if lbreakpos:
84 line = line[lbreakpos:] 103 line = line[lbreakpos:]
85 if self.writeline(line): 104 if self.writeline(filter_color(line)):
86 super().write(line) 105 super().write(line)
87 106
88 def writeline(self, line): 107 def writeline(self, line):
@@ -97,7 +116,7 @@ class BasicProgressHandler(ProgressHandler):
97 self._fire_progress(0) 116 self._fire_progress(0)
98 117
99 def write(self, string): 118 def write(self, string):
100 percs = self._regex.findall(string) 119 percs = self._regex.findall(filter_color(string))
101 if percs: 120 if percs:
102 progress = int(percs[-1]) 121 progress = int(percs[-1])
103 self.update(progress) 122 self.update(progress)
@@ -112,7 +131,7 @@ class OutOfProgressHandler(ProgressHandler):
112 self._fire_progress(0) 131 self._fire_progress(0)
113 132
114 def write(self, string): 133 def write(self, string):
115 nums = self._regex.findall(string) 134 nums = self._regex.findall(filter_color(string))
116 if nums: 135 if nums:
117 progress = (float(nums[-1][0]) / float(nums[-1][1])) * 100 136 progress = (float(nums[-1][0]) / float(nums[-1][1])) * 100
118 self.update(progress) 137 self.update(progress)