Skip to content

Commit a63b726

Browse files
committed
Container.exec_run returns a namedtuple w/ attrs exit_code & output
Signed-off-by: Frank Sachsenheim <[email protected]>
1 parent ad208df commit a63b726

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

docker/models/containers.py

Lines changed: 6 additions & 5 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,7 +150,7 @@ 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):
155155
Exit code for the executed command or ``None`` if
156156
either ``stream```or ``socket`` is ``True``.
@@ -172,10 +172,11 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
172172
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket
173173
)
174174
if socket or stream:
175-
return None, exec_output
175+
return ExecResult(None, exec_output)
176176
else:
177-
return (self.client.api.exec_inspect(resp['Id'])['ExitCode'],
178-
exec_output)
177+
return ExecResult(
178+
self.client.api.exec_inspect(resp['Id'])['ExitCode'],
179+
exec_output)
179180

180181
def export(self):
181182
"""

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)