From 68215e393d65eb8999fd3c26566cd7a331fe4300 Mon Sep 17 00:00:00 2001 From: Simon Law Date: Wed, 25 Jul 2012 13:16:51 -0400 Subject: settings.WKHTMLTOPDF_ENV can override environment variables. This is most usefully set to {'DISPLAY': ':1'} in production. This allows wkhtmltopdf access to a specific X headless server, since the server will not be running under X. --- wkhtmltopdf/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 69da74f..3172c42 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -3,6 +3,7 @@ from __future__ import absolute_import from copy import copy from itertools import chain from os import fdopen +import os import sys from tempfile import mkstemp import urllib @@ -74,12 +75,16 @@ def wkhtmltopdf(pages, output=None, **kwargs): options = copy(options) options.update(kwargs) + env = getattr(settings, 'WKHTMLTOPDF_ENV', None) + if env is not None: + env = dict(os.environ, **env) + cmd = getattr(settings, 'WKHTMLTOPDF_CMD', 'wkhtmltopdf') args = list(chain([cmd], _options_to_args(**options), list(pages), [output])) - return check_output(args, stderr=sys.stderr) + return check_output(args, stderr=sys.stderr, env=env) def template_to_temp_file(template_name, dictionary=None, context_instance=None): -- cgit v1.2.3