diff --git a/Makefile b/Makefile index 54bbe3151d..7a91ce8fbc 100644 --- a/Makefile +++ b/Makefile @@ -893,11 +893,5 @@ clean-elk: docker rm tools_elasticsearch_1 docker rm tools_kibana_1 -mongo-debug-ui: - docker run -it --rm --name mongo-express --link tools_mongo_1:mongo -e ME_CONFIG_OPTIONS_EDITORTHEME=ambiance -e ME_CONFIG_BASICAUTH_USERNAME=admin -e ME_CONFIG_BASICAUTH_PASSWORD=password -p 8081:8081 knickers/mongo-express - -mongo-container: - docker run -it --link tools_mongo_1:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/system_tracking_dev"' - psql-container: - docker run -it --link tools_postgres_1:postgres --rm postgres:9.4.1 sh -c 'exec psql -h "$$POSTGRES_PORT_5432_TCP_ADDR" -p "$$POSTGRES_PORT_5432_TCP_PORT" -U postgres' + docker run -it --net tools_default --rm postgres:9.4.1 sh -c 'exec psql -h "postgres" -p "5432" -U postgres' diff --git a/awx/api/views.py b/awx/api/views.py index 2182358999..6e53b6f3f0 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -3,11 +3,13 @@ # All Rights Reserved. # Python +import os import cgi import datetime import dateutil import time import socket +import subprocess import sys import logging from base64 import b64encode @@ -20,7 +22,7 @@ from django.core.cache import cache from django.core.urlresolvers import reverse from django.core.exceptions import FieldError from django.db.models import Q, Count -from django.db import IntegrityError, transaction +from django.db import IntegrityError, transaction, connection from django.shortcuts import get_object_or_404 from django.utils.encoding import smart_text, force_text from django.utils.safestring import mark_safe @@ -3859,6 +3861,17 @@ class UnifiedJobStdout(RetrieveAPIView): elif request.accepted_renderer.format == 'ansi': return Response(unified_job.result_stdout_raw) elif request.accepted_renderer.format in {'txt_download', 'ansi_download'}: + if not os.path.exists(unified_job.result_stdout_file): + write_fd = open(unified_job.result_stdout_file, 'w') + with connection.cursor() as cursor: + try: + cursor.copy_expert("copy (select stdout from main_jobevent where job_id={} order by start_line) to stdout".format(unified_job.id), + write_fd) + write_fd.close() + subprocess.Popen("sed -i 's/\\\\r\\\\n/\\n/g' {}".format(unified_job.result_stdout_file), + shell=True).wait() + except Exception as e: + return Response({"error": _("Error generating stdout download file: {}".format(e))}) try: content_fd = open(unified_job.result_stdout_file, 'r') if request.accepted_renderer.format == 'txt_download':