|
17 | 17 |
|
18 | 18 | from more_itertools import consume
|
19 | 19 |
|
| 20 | +from datalad_next.consts import COPY_BUFSIZE |
20 | 21 | from datalad_next.itertools import align_pattern
|
21 | 22 | from datalad_next.runners.iter_subproc import (
|
22 | 23 | OutputFrom,
|
|
29 | 30 |
|
30 | 31 | @contextmanager
|
31 | 32 | def shell_connection(shell_cmd: list[str],
|
| 33 | + *, |
| 34 | + chunk_size: int = COPY_BUFSIZE |
32 | 35 | ) -> Generator[ShellCommandExecutor, None, None]:
|
33 | 36 | """Context manager that provides an interactive connection to a shell
|
34 | 37 |
|
@@ -64,6 +67,7 @@ def train(queue: Queue):
|
64 | 67 | subprocess_inputs: Queue = Queue()
|
65 | 68 | with iter_subproc(shell_cmd,
|
66 | 69 | input=train(subprocess_inputs),
|
| 70 | + chunk_size=chunk_size, |
67 | 71 | bufsize=0) as shell_output:
|
68 | 72 | cmd_executor = ShellCommandExecutor(subprocess_inputs, shell_output)
|
69 | 73 | try:
|
@@ -170,7 +174,9 @@ def upload(self,
|
170 | 174 | -------
|
171 | 175 | tuple[int, bytes]
|
172 | 176 | A tuple containing the return code of the command that was executed
|
173 |
| - to upload the content and the last 64k bytes of stderr output |
| 177 | + to upload the file and the last ``chunk_size`` (defined by the |
| 178 | + ``chunk_size`` keyword argument to func:`shell_connection`) bytes |
| 179 | + of stderr output. |
174 | 180 | """
|
175 | 181 | file_size = local_path.stat().st_size
|
176 | 182 | cmd_line = f'dd bs=1 of="{remote_path.as_posix()}" count={file_size}'
|
@@ -199,7 +205,9 @@ def download(self,
|
199 | 205 | -------
|
200 | 206 | tuple[int, bytes]
|
201 | 207 | A tuple containing the return code of the command that was executed
|
202 |
| - to upload the content and the last 64k bytes of stderr output |
| 208 | + to download the file and the last ``chunk_size`` (defined by the |
| 209 | + ``chunk_size`` keyword argument to func:`shell_connection`) bytes |
| 210 | + of stderr output. |
203 | 211 | """
|
204 | 212 | # We use 7z in gzip-mode to compress the data that is sent over the
|
205 | 213 | # wire. That ensures that the end-marker is not in the downloaded data,
|
@@ -231,7 +239,9 @@ def delete(self,
|
231 | 239 | -------
|
232 | 240 | tuple[int, bytes]
|
233 | 241 | A tuple containing the return code of the command that was executed
|
234 |
| - to delete the files and the last 64k bytes of stderr output. |
| 242 | + to delete the files and the last ``chunk_size`` (defined by the |
| 243 | + ``chunk_size`` keyword argument to func:`shell_connection`) bytes |
| 244 | + of stderr output. |
235 | 245 | """
|
236 | 246 | cmd_line = \
|
237 | 247 | 'rm ' \
|
@@ -261,7 +271,11 @@ class ShellCommandResponseGenerator(ABCGenerator):
|
261 | 271 | :class:`ShellCommandExecutor`. It yields all bytes that the executed
|
262 | 272 | command writes to its ``stdout``. Once the command is finished, the
|
263 | 273 | generator will be exhausted. At this time, the return code of the command
|
264 |
| - can be retrieved from the ``code``-attribute of the generator. |
| 274 | + can be retrieved from the ``code``-attribute of the generator. The last |
| 275 | + ``chunk_size`` (defined by the ``chunk_size`` keyword argument to |
| 276 | + func:`shell_connection`) bytes of the stderr-output of the command are |
| 277 | + available in the ``stderr_dequeue``-attribute, which contains a |
| 278 | + ``deque``-object that holds individual stderr chunks. |
265 | 279 | """
|
266 | 280 | def __init__(self,
|
267 | 281 | stdout: OutputFrom,
|
|
0 commit comments