1
1
import copy
2
+ from collections import namedtuple
2
3
3
4
from ..api import APIClient
4
5
from ..errors import (ContainerError , ImageNotFound ,
@@ -150,9 +151,10 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
150
151
workdir (str): Path to working directory for this exec session
151
152
152
153
Returns:
153
- (tuple ): A tuple of (exit_code, output)
154
+ (ExecResult ): A tuple of (exit_code, output)
154
155
exit_code: (int):
155
- Exit code for the executed command
156
+ Exit code for the executed command or ``None`` if
157
+ either ``stream```or ``socket`` is ``True``.
156
158
output: (generator or str):
157
159
If ``stream=True``, a generator yielding response chunks.
158
160
If ``socket=True``, a socket object for the connection.
@@ -170,10 +172,13 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
170
172
exec_output = self .client .api .exec_start (
171
173
resp ['Id' ], detach = detach , tty = tty , stream = stream , socket = socket
172
174
)
173
- exit_code = 0
174
- if stream is False :
175
- exit_code = self .client .api .exec_inspect (resp ['Id' ])['ExitCode' ]
176
- return (exit_code , exec_output )
175
+ if socket or stream :
176
+ return ExecResult (None , exec_output )
177
+
178
+ return ExecResult (
179
+ self .client .api .exec_inspect (resp ['Id' ])['ExitCode' ],
180
+ exec_output
181
+ )
177
182
178
183
def export (self ):
179
184
"""
@@ -1004,3 +1009,8 @@ def _host_volume_from_bind(bind):
1004
1009
return bits [0 ]
1005
1010
else :
1006
1011
return bits [1 ]
1012
+
1013
+
1014
+ ExecResult = namedtuple ('ExecResult' , 'exit_code,output' )
1015
+ """ A result of Container.exec_run with the properties ``exit_code`` and
1016
+ ``output``. """
0 commit comments