From eae470eaaa1d3c95f8e58c5296ed28a01bcd74aa Mon Sep 17 00:00:00 2001 From: Simon Law Date: Fri, 20 Jul 2012 14:41:30 -0400 Subject: wkhtmltopdf() uses subprocess.check_output() instead of a custom Popen call. --- wkhtmltopdf/utils.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'wkhtmltopdf/utils.py') diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index cf01f43..7994a39 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -1,11 +1,14 @@ +from __future__ import absolute_import + from os import fdopen -from subprocess import Popen, PIPE, CalledProcessError from tempfile import mkstemp from django.conf import settings from django.template import loader from django.utils.encoding import smart_str +from .subprocess import check_output + WKHTMLTOPDF_CMD = getattr(settings, 'WKHTMLTOPDF_CMD', 'wkhtmltopdf') def wkhtmltopdf(pages, output=None, **kwargs): @@ -45,17 +48,8 @@ def wkhtmltopdf(pages, output=None, **kwargs): kwargs['quiet'] = '' args = '%s %s %s %s' % (WKHTMLTOPDF_CMD, _extra_args(**kwargs), ' '.join(pages), output or '-') + return check_output(args, shell=True) - process = Popen(args, stdout=PIPE, shell=True) - stdoutdata, stderrdata = process.communicate() - - if process.returncode != 0: - raise CalledProcessError(process.returncode, args) - - if output is None: - output = stdoutdata - - return output def template_to_temp_file(template_name, dictionary=None, context_instance=None): """ -- cgit v1.2.3