From d23ce1b4dbf9a32e7a8c1380b57956b6b2ada514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Sz=C5=91ke?= Date: Sat, 25 Jan 2025 13:27:49 +0100 Subject: [PATCH] bitbake: progressbar: Add self._fd_console to use for self._handle_resize() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce self._fd_console as a dedicated attribute of self._handle_resize(). (Bitbake rev: f8c76eb89d52b1c28407f0b52dfe4318faa47cd2) Signed-off-by: Benjamin Szőke Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- bitbake/lib/progressbar/progressbar.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bitbake/lib/progressbar/progressbar.py b/bitbake/lib/progressbar/progressbar.py index d4da10ab75..eccc45849b 100644 --- a/bitbake/lib/progressbar/progressbar.py +++ b/bitbake/lib/progressbar/progressbar.py @@ -110,18 +110,25 @@ class ProgressBar(object): self.widgets = widgets self.fd = fd self.left_justify = left_justify + self._fd_console = None self.signal_set = False if term_width is not None: self.term_width = term_width else: try: + # Check if given file descriptor is resizable for example belong + # to a terminal/console as STDOUT or STDERR. If file descriptor + # is resizable, let's allow to use for self._handle_resize() + # in a dedicated self._fd_console in order to be able to set + # temporarily/permanently self.fd to any StringIO or other + # file descriptor later. + self._fd_console = fd self._handle_resize(None, None) signal.signal(signal.SIGWINCH, self._handle_resize) self.signal_set = True except (SystemExit, KeyboardInterrupt): raise except Exception as e: - print("DEBUG 5 %s" % e) self.term_width = self._env_size() self.__iterable = None @@ -182,7 +189,7 @@ class ProgressBar(object): def _handle_resize(self, signum=None, frame=None): """Tries to catch resize signals sent from the terminal.""" - h, w = array('h', ioctl(self.fd, termios.TIOCGWINSZ, '\0' * 8))[:2] + h, w = array('h', ioctl(self._fd_console, termios.TIOCGWINSZ, '\0' * 8))[:2] self.term_width = w