-
Notifications
You must be signed in to change notification settings - Fork 6
Fix #8 Add basic stdin support to Subprocess and Paramiko #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #8 Add basic stdin support to Subprocess and Paramiko #20
Conversation
Pull Request Test Coverage Report for Build 83
💛 - Coveralls |
Pull Request Test Coverage Report for Build 73
💛 - Coveralls |
I missed 2nd part for SSH (it should look like copy-paste from Subprocess now, just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's Update ExecResult
arguments order (the single object, where it's technically allowed) and reduce encode/decode operations
doc/source/ExecResult.rst
Outdated
Command execution result. | ||
|
||
.. py:method:: __init__(cmd, stdout=None, stderr=None, exit_code=ExitCodes.EX_INVALID) | ||
.. py:method:: __init__(cmd, stdout=None, stderr=None, exit_code=ExitCodes.EX_INVALID, stdin=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably for ExecResult
we can use urder: stdin, stdout, stderr
as human-expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed that's more natural. I added it at the end only for consistency with the rest (where stdin is the latest for backward compatibility).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExecResult
class is exported for typing purposes only. It was not expected for re-use outside, except reading
exec_helpers/subprocess_runner.py
Outdated
) | ||
if stdin is not None: | ||
if not isinstance(stdin, six.text_type): | ||
stdin = six.u(stdin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to decode for ExecResult
inside ExecResult
and encode for stdin only if required (less transformations)
test/test_subprocess_runner.py
Outdated
def test_check_stdin(self, check_call, logger): | ||
print_stdin = 'cat <&0' | ||
stdin = 'input data' | ||
if not isinstance(stdin, six.text_type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have full control over tests - better to test both cases:
stdin = b'input data
and stdin = u'input data'
doc/source/ExecResult.rst
Outdated
:param cmd: command | ||
:type cmd: ``str`` | ||
:param stdout: STDIN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy-paste error: should be :param stdin: STDIN
and on the next line :type stdin: ...
doc/source/SSHClient.rst
Outdated
:param open_stderr: open STDERR stream for read | ||
:type open_stderr: bool | ||
:param stdin: pass STDIN text to the process | ||
:type stdin: ``typing.Optional[str]`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typing.Optional[bytes]
and need to check for bytearray
support (both Subprocess and SSH)
doc/source/Subprocess.rst
Outdated
.. versionchanged:: 1.2.0 | ||
|
||
open_stdout and open_stderr flags | ||
open_stdout, open_stderr and stdin flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdin separately - it's not flag, but data
exec_helpers/_ssh_client_base.py
Outdated
|
||
stdin = chan.makefile('wb') | ||
_stdin = chan.makefile('wb') | ||
if stdin is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sudo should be processed before
exec_helpers/exec_result.py
Outdated
|
||
self.__cmd = cmd | ||
if stdin is not None and not isinstance(stdin, six.text_type): | ||
stdin = six.u(stdin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdin = stdin.decode('utf-8')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not six.text_type
identifies e.g. non-unicode strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> b'dede'.decode('utf-8')
'dede'
Decode non-unicode to unicode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and for exec_result errors='backslashreplace'
is actual parameter, because we can have true binary data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see
exec_helpers/_ssh_client_base.py
Outdated
paramiko.ChannelFile, | ||
typing.Optional[paramiko.ChannelFile], | ||
typing.Optional[paramiko.ChannelFile], | ||
typing.Any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not change this, typing.Any will be used in the base class later (2.0.0+)
:param command: Command for execution | ||
:type command: str | ||
:param get_pty: open PTY on remote machine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this argument is not removed
verbose=False, # type: bool | ||
log_mask_re=None, # type: typing.Optional[str] | ||
**kwargs | ||
): # type: (...) -> _type_execute_async |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not remove this typing
exec_helpers/_ssh_client_base.py
Outdated
return chan, stdin, stderr, stdout | ||
if stdin is not None: | ||
if not isinstance(stdin, six.text_type): | ||
stdin = six.u(stdin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use encode/decode
doc/source/ExecResult.rst
Outdated
:param cmd: command | ||
:type cmd: ``str`` | ||
:param stdin: STDIN | ||
:type stdin: ``str`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typing.Optional[str]
exec_helpers/_ssh_client_base.py
Outdated
.. versionchanged:: 1.2.0 open_stdout and open_stderr flags | ||
.. versionchanged:: 1.2.0 | ||
open_stdout and open_stderr flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make several records like Subprocess.rst
exec_helpers/subprocess_runner.py
Outdated
from __future__ import unicode_literals | ||
|
||
import collections | ||
import errno |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linux only -> we need separation linux/posix/windows
What do these changes do?
Add basic stdin support to Subprocess and Paramiko.
Are there changes in behavior for the user?
The user can provide some content for stdin that will be available to the process.
Related issue number
Fix #8
Checklist