Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import re
import io
import os
import sys
from . import Image, ImageFile
from ._binary import i32le as i32, o32le as o32
Expand Down Expand Up @@ -57,8 +58,8 @@ def has_ghostscript():
if not sys.platform.startswith('win'):
import subprocess
try:
gs = subprocess.Popen(['gs', '--version'], stdout=subprocess.PIPE)
gs.stdout.read()
with open(os.devnull, 'wb') as devnull:
subprocess.check_call(['gs', '--version'], stdout=devnull)
return True
except OSError:
# no ghostscript
Expand Down Expand Up @@ -137,12 +138,8 @@ def Ghostscript(tile, size, fp, scale=1):

# push data through ghostscript
try:
gs = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
gs.stdin.close()
status = gs.wait()
if status:
raise IOError("gs failed (status %d)" % status)
with open(os.devnull, 'w+b') as devnull:
subprocess.check_call(command, stdin=devnull, stdout=devnull)
im = Image.open(outfile)
im.load()
finally:
Expand Down
11 changes: 5 additions & 6 deletions PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,17 @@ def _save_netpbm(im, fp, filename):

with open(filename, 'wb') as f:
if im.mode != "RGB":
with tempfile.TemporaryFile() as stderr:
check_call(["ppmtogif", file], stdout=f, stderr=stderr)
with open(os.devnull, 'wb') as devnull:
check_call(["ppmtogif", file], stdout=f, stderr=devnull)
else:
# Pipe ppmquant output into ppmtogif
# "ppmquant 256 %s | ppmtogif > %s" % (file, filename)
quant_cmd = ["ppmquant", "256", file]
togif_cmd = ["ppmtogif"]
with tempfile.TemporaryFile() as stderr:
quant_proc = Popen(quant_cmd, stdout=PIPE, stderr=stderr)
with tempfile.TemporaryFile() as stderr:
with open(os.devnull, 'wb') as devnull:
quant_proc = Popen(quant_cmd, stdout=PIPE, stderr=devnull)
togif_proc = Popen(togif_cmd, stdin=quant_proc.stdout,
stdout=f, stderr=stderr)
stdout=f, stderr=devnull)

# Allow ppmquant to receive SIGPIPE if ppmtogif exits
quant_proc.stdout.close()
Expand Down
4 changes: 2 additions & 2 deletions PIL/IcnsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ def _save(im, fp, filename):
from subprocess import Popen, PIPE, CalledProcessError

convert_cmd = ["iconutil", "-c", "icns", "-o", filename, iconset]
with tempfile.TemporaryFile() as stderr:
convert_proc = Popen(convert_cmd, stdout=PIPE, stderr=stderr)
with open(os.devnull, 'wb') as devnull:
convert_proc = Popen(convert_cmd, stdout=PIPE, stderr=devnull)

convert_proc.stdout.close()

Expand Down
12 changes: 6 additions & 6 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,25 @@ def command_succeeds(cmd):
command succeeds, or False if an OSError was raised by subprocess.Popen.
"""
import subprocess
with open(os.devnull, 'w') as f:
with open(os.devnull, 'wb') as f:
try:
subprocess.Popen(cmd, stdout=f, stderr=subprocess.STDOUT).wait()
subprocess.call(cmd, stdout=f, stderr=subprocess.STDOUT)
except OSError:
return False
return True


def djpeg_available():
return command_succeeds(['djpeg', '--help'])
return command_succeeds(['djpeg', '-version'])


def cjpeg_available():
return command_succeeds(['cjpeg', '--help'])
return command_succeeds(['cjpeg', '-version'])


def netpbm_available():
return (command_succeeds(["ppmquant", "--help"]) and
command_succeeds(["ppmtogif", "--help"]))
return (command_succeeds(["ppmquant", "--version"]) and
command_succeeds(["ppmtogif", "--version"]))


def imagemagick_available():
Expand Down