bitbake: progressbar: Add self._fd_console to use for self._handle_resize()

Introduce self._fd_console as a dedicated attribute of self._handle_resize().

(Bitbake rev: f8c76eb89d52b1c28407f0b52dfe4318faa47cd2)

Signed-off-by: Benjamin Szőke <egyszeregy@freemail.hu>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Benjamin Szőke
2025-01-25 13:27:49 +01:00
committed by Richard Purdie
parent 5dce840ba8
commit d23ce1b4db

View File

@@ -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