summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/progress.py
diff options
context:
space:
mode:
authorChris Laplante <chris.laplante@agilent.com>2019-06-07 14:24:03 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-06-11 13:27:19 +0100
commit768746959089f8fa0e6e73f3917abebfae22d652 (patch)
tree725e6adda21da39972116010f8a4e4fe0dc3cc39 /bitbake/lib/bb/progress.py
parent575ea5532f80883f8ee20dd1e78f699e8dccafc5 (diff)
downloadpoky-768746959089f8fa0e6e73f3917abebfae22d652.tar.gz
bitbake: build/progress: use context managers for progress handlers
It seems context management support was half-implemented, but never finished. For example, LogTee has __enter__ and __exit__ but they haven't been exercised until now. (Bitbake rev: bf522ad3e0c52cdb69b406226840d870ff4f2766) Signed-off-by: Chris Laplante <chris.laplante@agilent.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/progress.py')
-rw-r--r--bitbake/lib/bb/progress.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/bitbake/lib/bb/progress.py b/bitbake/lib/bb/progress.py
index e9b72e28b9..4022caa717 100644
--- a/bitbake/lib/bb/progress.py
+++ b/bitbake/lib/bb/progress.py
@@ -13,6 +13,7 @@ import time
13import inspect 13import inspect
14import bb.event 14import bb.event
15import bb.build 15import bb.build
16from bb.build import StdoutNoopContextManager
16 17
17class ProgressHandler(object): 18class ProgressHandler(object):
18 """ 19 """
@@ -27,7 +28,14 @@ class ProgressHandler(object):
27 if outfile: 28 if outfile:
28 self._outfile = outfile 29 self._outfile = outfile
29 else: 30 else:
30 self._outfile = sys.stdout 31 self._outfile = StdoutNoopContextManager()
32
33 def __enter__(self):
34 self._outfile.__enter__()
35 return self
36
37 def __exit__(self, *excinfo):
38 self._outfile.__exit__(*excinfo)
31 39
32 def _fire_progress(self, taskprogress, rate=None): 40 def _fire_progress(self, taskprogress, rate=None):
33 """Internal function to fire the progress event""" 41 """Internal function to fire the progress event"""
@@ -147,6 +155,12 @@ class MultiStageProgressReporter(object):
147 self._stage_total = None 155 self._stage_total = None
148 self._callers = [] 156 self._callers = []
149 157
158 def __enter__(self):
159 return self
160
161 def __exit__(self, *excinfo):
162 pass
163
150 def _fire_progress(self, taskprogress): 164 def _fire_progress(self, taskprogress):
151 bb.event.fire(bb.build.TaskProgress(taskprogress), self._data) 165 bb.event.fire(bb.build.TaskProgress(taskprogress), self._data)
152 166