Skip to content

Commit

Permalink
Output docker-compose up to stdout without buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Narea committed Aug 22, 2016
1 parent 34faacd commit ee010cd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0a2
1.0a3
10 changes: 8 additions & 2 deletions docker_dev/docker_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ def run_docker_compose_subcommand(
subcommand_name,
subcommand_args,
docker_compose_file_path,
project_name
project_name,
return_stdout=True,
):
project_file_arg = '--file={}'.format(docker_compose_file_path)
command_args = [project_file_arg, subcommand_name] + subcommand_args
command_environ = {'COMPOSE_PROJECT_NAME': project_name}
output = run_command('docker-compose', command_args, command_environ)
output = run_command(
'docker-compose',
command_args,
command_environ,
return_stdout,
)
return output


Expand Down
1 change: 1 addition & 0 deletions docker_dev/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def run_project(docker_compose_file_path, project_name):
['--force-recreate', '--abort-on-container-exit'],
docker_compose_file_path,
project_name,
return_stdout=False,
)


Expand Down
21 changes: 16 additions & 5 deletions docker_dev/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
# INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
#
##############################################################################
from io import BytesIO
from locale import getpreferredencoding
from os import environ
from subprocess import CalledProcessError
from subprocess import check_output
from subprocess import CalledProcessError, check_call
from sys import stdout
from tempfile import TemporaryFile

from docker_dev.exceptions import SubprocessError, \
Expand All @@ -26,15 +27,23 @@
_SYSTEM_ENCODING = getpreferredencoding()


def run_command(command_name, command_args, additional_environ=None, **kwargs):
def run_command(
command_name,
command_args,
additional_environ=None,
return_stdout=True,
**kwargs
):
command_parts = [command_name] + command_args
additional_environ = additional_environ or {}
command_environ = dict(additional_environ, PATH=environ['PATH'])
command_stdout = BytesIO() if return_stdout else stdout
command_stderr = TemporaryFile()
try:
command_stdout_bytes = check_output(
check_call(
command_parts,
env=command_environ,
stdout=command_stdout,
stderr=command_stderr,
**kwargs
)
Expand All @@ -47,6 +56,8 @@ def run_command(command_name, command_args, additional_environ=None, **kwargs):
)
except FileNotFoundError:
raise MissingCommandError(command_name)
else:

if return_stdout:
command_stdout_bytes = command_stdout.getvalue()
command_stdout_str = command_stdout_bytes.decode(_SYSTEM_ENCODING)
return command_stdout_str.rstrip()

0 comments on commit ee010cd

Please sign in to comment.