diff options
author | Simon Law <simon.law@ecometrica.com> | 2012-07-20 14:41:30 -0400 |
---|---|---|
committer | Simon Law <simon.law@ecometrica.com> | 2012-07-20 14:41:30 -0400 |
commit | eae470eaaa1d3c95f8e58c5296ed28a01bcd74aa (patch) | |
tree | d5807412e33c624ea58479887f48b27fd54b5eca /wkhtmltopdf/utils.py | |
parent | df83b5a8045d1fe69b3ae4d5ffdc5f98069862dc (diff) | |
download | django-wkhtmltopdf-eae470eaaa1d3c95f8e58c5296ed28a01bcd74aa.tar.gz django-wkhtmltopdf-eae470eaaa1d3c95f8e58c5296ed28a01bcd74aa.tar.bz2 django-wkhtmltopdf-eae470eaaa1d3c95f8e58c5296ed28a01bcd74aa.zip |
wkhtmltopdf() uses subprocess.check_output() instead of a custom Popen call.
Diffstat (limited to 'wkhtmltopdf/utils.py')
-rw-r--r-- | wkhtmltopdf/utils.py | 16 |
1 files changed, 5 insertions, 11 deletions
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): """ |