Uploaded image for project: 'RHEL Conversions'
  1. RHEL Conversions
  2. RHELC-570

Clean up the pexpect terminal window size handling

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major Major
    • 1.0
    • None
    • None
    • False
    • False
    • Hide

      None

      Show
      None
    • 3
    • 2022-Q3

      Setting the pexpect terminal window size is tricky because we need the window size to be set before the process starts (otherwise some programs like yumdownloader will truncate output that we're scanning for). On RHEL7, we currently work around this by creating a subclass which sets the window size by relying on internal implementation details of pexpect. pexpect's _init_() calls setwinsize(). By overriding setwinsize() to hardcode 120 columns, we can set the terminal size to 120 columns at startup.

      On RHEL8, _init_() does not call setwinsize() so that no longer works. Instead, we should call spawn() with dimensions=(1, 120). The dimensions set the rows and columns on startup like we want. This was added in 2015, so it isn't available on RHEL7 but it is available on RHEL8.

      Code which tries to use dimensions and then uses the subclass hack if that doesn't exist is probably the best way to do this:
      {{try:
      process = pexpect.spawn(cmd[0], cmd[1:], timeout=None, dimensions=(1, columns))
      except TypeError:
      process = PexpectSizedWindowSpawn(cmd[0], cmd[1:], timeout=None)
      }}

      We can removed our explicit call to setwinsize() in run_cmd_in_pty() once we've done this as it was there to handle the RHEL8 case, but does so after the process starts so our code to set it via dimensions is better.

              tkuratom@redhat.com Toshio Kuratomi
              tkuratom@redhat.com Toshio Kuratomi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: