Fix Ghostscript command on Windows

This commit is contained in:
Kyle MacFarlane 2013-03-06 17:36:22 +00:00
parent 5c9c5e45fd
commit de17144f6b

View File

@ -33,8 +33,25 @@ o32 = _binary.o32le
split = re.compile(r"^%%([^:]*):[ \t]*(.*)[ \t]*$")
field = re.compile(r"^%[%!\w]([^:]*)[ \t]*$")
gs_windows_binary = None
import sys
if sys.platform[:3].lower() == 'win':
import shutil
if hasattr(shutil, 'which'):
which = shutil.which
else:
# Python < 3.3
import distutils
which = distutils.spawn.find_executable
for binary in ('gswin32c', 'gswin64c', 'gs'):
if which(binary) is not None:
gs_windows_binary = binary
break
else:
gs_windows_binary = False
def Ghostscript(tile, size, fp):
"""Render an image using Ghostscript (Unix only)"""
"""Render an image using Ghostscript"""
# Unpack decoder tile
decoder, tile, offset, data = tile[0]
@ -53,6 +70,12 @@ def Ghostscript(tile, size, fp):
"-sOutputFile=%s" % file,# output file
"- >/dev/null 2>/dev/null"]
if gs_windows_binary is not None:
if gs_windows_binary is False:
raise WindowsError('Unable to locate Ghostscript on paths')
command[0] = gs_windows_binary
command[-1] = '- >nul 2>nul'
command = " ".join(command)
# push data through ghostscript