Skip to content

Commit 600cc15

Browse files
committed
Merge branch 'container_exec_run' of https://github.com/funkyfuture/docker-py into funkyfuture-container_exec_run
Signed-off-by: Joffrey F <[email protected]>
2 parents 5728eeb + a63b726 commit 600cc15

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

docker/models/containers.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from ..api import APIClient
44
from ..errors import (ContainerError, ImageNotFound,
55
create_unexpected_kwargs_error)
6-
from ..types import HostConfig
6+
from ..types import ExecResult, HostConfig
77
from ..utils import version_gte
88
from .images import Image
99
from .resource import Collection, Model
@@ -150,9 +150,10 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
150150
workdir (str): Path to working directory for this exec session
151151
152152
Returns:
153-
(tuple): A tuple of (exit_code, output)
153+
(ExecResult): A tuple of (exit_code, output)
154154
exit_code: (int):
155-
Exit code for the executed command
155+
Exit code for the executed command or ``None`` if
156+
either ``stream```or ``socket`` is ``True``.
156157
output: (generator or str):
157158
If ``stream=True``, a generator yielding response chunks.
158159
If ``socket=True``, a socket object for the connection.
@@ -170,10 +171,12 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
170171
exec_output = self.client.api.exec_start(
171172
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket
172173
)
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)
174+
if socket or stream:
175+
return ExecResult(None, exec_output)
176+
else:
177+
return ExecResult(
178+
self.client.api.exec_inspect(resp['Id'])['ExitCode'],
179+
exec_output)
177180

178181
def export(self):
179182
"""

docker/types/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# flake8: noqa
2-
from .containers import ContainerConfig, HostConfig, LogConfig, Ulimit
2+
from .containers import (ContainerConfig, ExecResult, HostConfig, LogConfig,
3+
Ulimit)
34
from .healthcheck import Healthcheck
45
from .networks import EndpointConfig, IPAMConfig, IPAMPool, NetworkingConfig
56
from .services import (

docker/types/containers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import namedtuple
12
import six
23
import warnings
34

@@ -11,6 +12,11 @@
1112
from .healthcheck import Healthcheck
1213

1314

15+
ExecResult = namedtuple('ExecResult', 'exit_code,output')
16+
""" A result of Container.exec_run with the properties ``exit_code`` and
17+
``output``. """
18+
19+
1420
class LogConfigTypesEnum(object):
1521
_values = (
1622
'json-file',

0 commit comments

Comments
 (0)