Add stderr/stdin stream control for console utilities.

Review Request #12246 — Created April 21, 2022 and submitted

Information

RBTools
release-3.x

Reviewers

This adds stderr and stdin control for get_input(), get_pass(),
confirm(), and confirm_select() utilities. When hooked up properly,
this enables unit tests to automate code paths that require user input.

If stdin is a TTY, these will prompt the user for input as normal.
Otherwise, they'll read a line from stdin. This allows for scripting
inputs.

While here, a few additional tweaks were made to these very old
utilities:

  • confirm() no longer uses a private method in distutils to check
    for Yes/No input strings. Instead, the checks are now under our
    control.

  • confirm() and confirm_select() now show bad user input in quotes.

Unit tests were also added for all these functions.

Unit tests pass.

Summary ID
Add stderr/stdin stream control for console utilities.
This adds `stderr` and `stdin` control for `get_input()`, `get_pass()`, `confirm()`, and `confirm_select()` utilities. When hooked up properly, this enables unit tests to automate code paths that require user input. If `stdin` is a TTY, these will prompt the user for input as normal. Otherwise, they'll read a line from `stdin`. This allows for scripting inputs. While here, a few additional tweaks were made to these very old utilities: * `confirm()` no longer uses a private method in `distutils` to check for Yes/No input strings. Instead, the checks are now under our control. * `confirm()` and `confirm_select()` now show bad user input in quotes. Unit tests were also added for all these functions.
7466ee80285d0ccac2482267f449e6baf0714927
Description From Last Updated

I need to spend a little more time thinking about how this interacts with things like piping a diff filename... …

chipx86chipx86
chipx86
  1. 
      
  2. I need to spend a little more time thinking about how this interacts with things like piping a diff filename... There wouldn't be anything to read after consuming the diff (assuming we read it before invoking any of these commands), and we could then infinite loop on some of these...

    This isn't necessarily a blocker for the other work I have in progress. I'll mull it over.

    1. Ran a quick test. I think nothing actually changes. getpass() doesn't care about stdin when asking (it opens a TTY). input() is affected by stdin, but that'd have been the case already, so no difference in behavior there. And we're using sys.stdin by default anyway. So this all should be safe.

  3. 
      
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-3.x (2e69a5b)
Loading...