Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions src/local_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ def popen(
text: typing.Optional[bool] = None,
encoding: typing.Optional[str] = None,
shell: bool = False,
stdin: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdout: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stderr: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdin: typing.Optional[T_OS_IO_ID] = None,
stdout: typing.Optional[T_OS_IO_ID] = None,
stderr: typing.Optional[T_OS_IO_ID] = None,
exec_env: typing.Optional[T_OS_EXEC_ENV] = None,
cwd: typing.Optional[str] = None
) -> OsProcessController:
Expand Down Expand Up @@ -560,9 +560,9 @@ def popen(
result._local_process = subprocess.Popen(
cmd,
shell=shell,
stdin=stdin,
stdout=stdout,
stderr=stderr,
stdin=self._get_stdin(stdin, None),
stdout=self._get_stdout(stdout),
stderr=self._get_stderr(stderr),
text=text,
encoding=encoding,
cwd=cwd,
Expand All @@ -578,9 +578,9 @@ def run(
encoding: typing.Optional[str] = None,
shell: bool = False,
input: typing.Optional[T_OS_EXEC_INPUT] = None,
stdin: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdout: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stderr: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdin: typing.Optional[T_OS_IO_ID] = None,
stdout: typing.Optional[T_OS_IO_ID] = None,
stderr: typing.Optional[T_OS_IO_ID] = None,
exec_env: typing.Optional[T_OS_EXEC_ENV] = None,
cwd: typing.Optional[str] = None,
timeout: typing.Optional[T_OS_TIMEOUT] = None,
Expand All @@ -604,7 +604,7 @@ def run(
text=text,
encoding=encoding,
shell=shell,
stdin=stdin,
stdin=self._get_stdin(stdin, input),
stdout=stdout,
stderr=stderr,
exec_env=exec_env,
Expand Down Expand Up @@ -1186,3 +1186,37 @@ def _set_env(
else:
os.environ[var_name] = var_val
return

def _get_stdin(
self,
stdin: typing.Optional[T_OS_IO_ID],
input: typing.Optional[T_OS_EXEC_INPUT],
) -> typing.Optional[T_OS_IO_ID]:
if stdin is not None:
return stdin

if input is not None:
return subprocess.PIPE

# default
return subprocess.PIPE

def _get_stdout(
self,
stdout: typing.Optional[T_OS_IO_ID],
) -> typing.Optional[T_OS_IO_ID]:
if stdout is not None:
return stdout

# default
return subprocess.PIPE

def _get_stderr(
self,
stderr: typing.Optional[T_OS_IO_ID],
) -> typing.Optional[T_OS_IO_ID]:
if stderr is not None:
return stderr

# default
return subprocess.PIPE
12 changes: 6 additions & 6 deletions src/os_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ def popen(
text: typing.Optional[bool] = None,
encoding: typing.Optional[str] = None,
shell: bool = False,
stdin: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdout: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stderr: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdin: typing.Optional[T_OS_IO_ID] = None,
stdout: typing.Optional[T_OS_IO_ID] = None,
stderr: typing.Optional[T_OS_IO_ID] = None,
exec_env: typing.Optional[T_OS_EXEC_ENV] = None,
cwd: typing.Optional[str] = None
) -> OsProcessController:
Expand All @@ -238,9 +238,9 @@ def run(
encoding: typing.Optional[str] = None,
shell: bool = False,
input: typing.Optional[T_OS_EXEC_INPUT] = None,
stdin: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdout: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stderr: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdin: typing.Optional[T_OS_IO_ID] = None,
stdout: typing.Optional[T_OS_IO_ID] = None,
stderr: typing.Optional[T_OS_IO_ID] = None,
exec_env: typing.Optional[T_OS_EXEC_ENV] = None,
cwd: typing.Optional[str] = None,
timeout: typing.Optional[T_OS_TIMEOUT] = None,
Expand Down
106 changes: 87 additions & 19 deletions src/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@ def popen(
text: typing.Optional[bool] = None,
encoding: typing.Optional[str] = None,
shell: bool = False,
stdin: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdout: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stderr: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdin: typing.Optional[T_OS_IO_ID] = None,
stdout: typing.Optional[T_OS_IO_ID] = None,
stderr: typing.Optional[T_OS_IO_ID] = None,
exec_env: typing.Optional[T_OS_EXEC_ENV] = None,
cwd: typing.Optional[str] = None
) -> OsProcessController:
Expand Down Expand Up @@ -662,9 +662,9 @@ def popen(
# 2. Run a local SSH client in the background
result._local_process = subprocess.Popen(
ssh_cmd,
stdin=stdin,
stdout=stdout,
stderr=stderr,
stdin=self._get_stdin(stdin, None),
stdout=self._get_stdout(stdout),
stderr=self._get_stderr(stderr),
text=text,
encoding=encoding,
shell=False,
Expand Down Expand Up @@ -745,9 +745,9 @@ def run(
encoding: typing.Optional[str] = None,
shell: bool = False,
input: typing.Optional[T_OS_EXEC_INPUT] = None,
stdin: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdout: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stderr: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdin: typing.Optional[T_OS_IO_ID] = None,
stdout: typing.Optional[T_OS_IO_ID] = None,
stderr: typing.Optional[T_OS_IO_ID] = None,
exec_env: typing.Optional[T_OS_EXEC_ENV] = None,
cwd: typing.Optional[str] = None,
timeout: typing.Optional[T_OS_TIMEOUT] = None,
Expand Down Expand Up @@ -1783,9 +1783,9 @@ def _transport_popen(
text: typing.Optional[bool] = None,
encoding: typing.Optional[str] = None,
shell: bool = False,
stdin: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdout: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stderr: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdin: typing.Optional[T_OS_IO_ID] = None,
stdout: typing.Optional[T_OS_IO_ID] = None,
stderr: typing.Optional[T_OS_IO_ID] = None,
exec_env: typing.Optional[T_OS_EXEC_ENV] = None,
cwd: typing.Optional[str] = None
) -> subprocess.Popen:
Expand Down Expand Up @@ -1835,9 +1835,9 @@ def _transport_popen(

result = subprocess.Popen(
ssh_cmd,
stdin=stdin,
stdout=stdout,
stderr=stderr,
stdin=self._transport_get_stdin(stdin, None),
stdout=self._transport_get_stdout(stdout),
stderr=self._transport_get_stderr(stderr),
text=text,
encoding=encoding,
shell=False,
Expand Down Expand Up @@ -1874,9 +1874,9 @@ def _transport_run(
encoding: typing.Optional[str] = None,
shell: bool = False,
input: typing.Optional[T_OS_EXEC_INPUT] = None,
stdin: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdout: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stderr: typing.Optional[T_OS_IO_ID] = subprocess.PIPE,
stdin: typing.Optional[T_OS_IO_ID] = None,
stdout: typing.Optional[T_OS_IO_ID] = None,
stderr: typing.Optional[T_OS_IO_ID] = None,
exec_env: typing.Optional[T_OS_EXEC_ENV] = None,
cwd: typing.Optional[str] = None,
check: bool = True,
Expand All @@ -1902,7 +1902,7 @@ def _transport_run(
text=text,
encoding=encoding,
shell=shell,
stdin=stdin,
stdin=self._transport_get_stdin(stdin, input),
stdout=stdout,
stderr=stderr,
exec_env=exec_env,
Expand Down Expand Up @@ -1937,6 +1937,40 @@ def _transport_run(

return result

def _transport_get_stdin(
self,
stdin: typing.Optional[T_OS_IO_ID],
input: typing.Optional[T_OS_EXEC_INPUT],
) -> typing.Optional[T_OS_IO_ID]:
if stdin is not None:
return stdin

if input is not None:
return subprocess.PIPE

# default
return subprocess.PIPE

def _transport_get_stdout(
self,
stdout: typing.Optional[T_OS_IO_ID],
) -> typing.Optional[T_OS_IO_ID]:
if stdout is not None:
return stdout

# default
return subprocess.PIPE

def _transport_get_stderr(
self,
stderr: typing.Optional[T_OS_IO_ID],
) -> typing.Optional[T_OS_IO_ID]:
if stderr is not None:
return stderr

# default
return subprocess.PIPE

@staticmethod
def _build_cmdline(
cmd,
Expand Down Expand Up @@ -2111,6 +2145,40 @@ def _join_command_arguments(cmd: typing.Iterable[str]) -> str:

return " ".join(__class__._quote_path(arg) for arg in cmd)

def _get_stdin(
self,
stdin: typing.Optional[T_OS_IO_ID],
input: typing.Optional[T_OS_EXEC_INPUT],
) -> typing.Optional[T_OS_IO_ID]:
if stdin is not None:
return stdin

if input is not None:
return subprocess.PIPE

# default
return subprocess.PIPE

def _get_stdout(
self,
stdout: typing.Optional[T_OS_IO_ID],
) -> typing.Optional[T_OS_IO_ID]:
if stdout is not None:
return stdout

# default
return subprocess.PIPE

def _get_stderr(
self,
stderr: typing.Optional[T_OS_IO_ID],
) -> typing.Optional[T_OS_IO_ID]:
if stderr is not None:
return stderr

# default
return subprocess.PIPE


def normalize_error(error):
if isinstance(error, bytes):
Expand Down