Skip to content

Prompt/etc autoresponder #289

@bitprophet

Description

@bitprophet

This represents porting Fabric 1.x's limited ability to autorespond to sudo prompts, to Invoke, and making it Better™.

For now, I've gone with a basic "when you see X, always respond with Y" functionality that can be easily configured via a {pattern: response} dict.

This isn't the most powerful implementation; e.g. one might want "only respond to patterns once", "respond to X pattern the first 3 times only", "respond to pattern X but only if you've already responded to pattern Y", etc etc.

However it's arguably more flexible than using e.g. pexpect (which requires you to anticipate exactly what prompts will happen, in what order; Invoke/Fabric use cases tend to have prompts appear arbitrarily) and I expect it will be enhanced in the future, perhaps by ripping out the responder aspects into their own class or something.

The functionality is already pretty much complete after a ~week of hacking, fucking up, getting confused, becoming less confused, and more hacking. I'm making this ticket just so I have something to link in the changelog & a checklist for the random minor tasks left to perform.


Left to do:

  • Deal with recently-discovered funkiness in interactive stdin use case
  • Make sure the basic functionality works for Fabric 2 as well as with local/subprocess
  • Reinstate the Windows support for handle_input, which mirrors real stdin to the subprocess' stdin.
  • Doublecheck whether we actually need Windows getch as per Handle stdin on Windows using msvcrt functions #304 (comment)
  • Figure out whether to retain the sleep call in handle_input; git-blame the Fab 1 line and doublecheck the rationale. Probably do want it back tho, probably chews more CPU than it really needs to as-is.
  • Reinstate the "print read stdin data to stdout when pty=False" behavior from fab 1 - it is necessary
  • Ditto the "halt stdin mirroring while the local codebase is explicitly trying to prompt for shit it needs" functionality from Fab 1.
    • ...does this mean Fab 1 literally can't deal with users manually executing things like raw_input and getpass? Cuz if it can then that implies said halting/locking might not have been necessary? Or is a corner case?
    • See notes in desc of Convenient sudo() wrapper #294 - probably not going to go down the same road as in Fab 1 which means we wouldn't have to worry about this wrinkle.
  • Centralize & normalize the encoding related noise, as per comments by @pfmoore in comments below.
  • Try to replicate Pressing enter while running can expose sudo password fabric/fabric#1339 (both in Fabric 1, and here, and in Fabric 2)
  • Figure out if it's worth implementing a(n easily disabled and well documented!) convenience "add \n to response values if not present" feature.
  • Determine what's up with swallowed exceptions in the out/err/in threads when the main thread gets an eg KeyboardException. Feels like a thing we need to at least partially port from fab v1.
  • Python 3 test pass so Travis doesn't get mad at me
  • Ascertain why the test suite got slower again and how much of it's due to this branch
  • Double-check the doc situation; may want to make a "feature list!" section on index page?
  • Changelog entry

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions