aboutsummaryrefslogtreecommitdiffstats
path: root/wkhtmltopdf/utils.py
diff options
context:
space:
mode:
authorSimon Law <simon.law@ecometrica.com>2012-07-20 14:41:30 -0400
committerSimon Law <simon.law@ecometrica.com>2012-07-20 14:41:30 -0400
commiteae470eaaa1d3c95f8e58c5296ed28a01bcd74aa (patch)
treed5807412e33c624ea58479887f48b27fd54b5eca /wkhtmltopdf/utils.py
parentdf83b5a8045d1fe69b3ae4d5ffdc5f98069862dc (diff)
downloaddjango-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.py16
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):
"""