diff options
author | Chris Laplante <chris.laplante@agilent.com> | 2019-06-07 14:24:03 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-06-11 10:08:03 +0100 |
commit | bf522ad3e0c52cdb69b406226840d870ff4f2766 (patch) | |
tree | 7a561dabbd7027cbe7e9449c224ac408a63f71bb /lib/bb/progress.py | |
parent | a841efa50d3aaf7c57446806327b2b687371cb29 (diff) | |
download | bitbake-bf522ad3e0c52cdb69b406226840d870ff4f2766.tar.gz |
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.
Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/progress.py')
-rw-r--r-- | lib/bb/progress.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/bb/progress.py b/lib/bb/progress.py index e9b72e28b..4022caa71 100644 --- a/lib/bb/progress.py +++ b/lib/bb/progress.py @@ -13,6 +13,7 @@ import time import inspect import bb.event import bb.build +from bb.build import StdoutNoopContextManager class ProgressHandler(object): """ @@ -27,7 +28,14 @@ class ProgressHandler(object): if outfile: self._outfile = outfile else: - self._outfile = sys.stdout + self._outfile = StdoutNoopContextManager() + + def __enter__(self): + self._outfile.__enter__() + return self + + def __exit__(self, *excinfo): + self._outfile.__exit__(*excinfo) def _fire_progress(self, taskprogress, rate=None): """Internal function to fire the progress event""" @@ -147,6 +155,12 @@ class MultiStageProgressReporter(object): self._stage_total = None self._callers = [] + def __enter__(self): + return self + + def __exit__(self, *excinfo): + pass + def _fire_progress(self, taskprogress): bb.event.fire(bb.build.TaskProgress(taskprogress), self._data) |