mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Simplify using subprocess.DEVNULL
Co-Authored-By: Jon Dufresne <jon.dufresne@gmail.com>
This commit is contained in:
parent
6cd99fc3cf
commit
84e53e3757
|
@ -321,11 +321,10 @@ def command_succeeds(cmd):
|
|||
Runs the command, which must be a list of strings. Returns True if the
|
||||
command succeeds, or False if an OSError was raised by subprocess.Popen.
|
||||
"""
|
||||
with open(os.devnull, "wb") as f:
|
||||
try:
|
||||
subprocess.call(cmd, stdout=f, stderr=subprocess.STDOUT)
|
||||
except OSError:
|
||||
return False
|
||||
try:
|
||||
subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
||||
except OSError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
|
6
setup.py
6
setup.py
|
@ -164,10 +164,10 @@ def _find_library_dirs_ldconfig():
|
|||
expr = r".* => (.*)"
|
||||
env = {}
|
||||
|
||||
null = open(os.devnull, "wb")
|
||||
try:
|
||||
with null:
|
||||
p = subprocess.Popen(args, stderr=null, stdout=subprocess.PIPE, env=env)
|
||||
p = subprocess.Popen(
|
||||
args, stderr=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env
|
||||
)
|
||||
except OSError: # E.g. command not found
|
||||
return []
|
||||
[data, _] = p.communicate()
|
||||
|
|
|
@ -57,8 +57,7 @@ def has_ghostscript():
|
|||
return True
|
||||
if not sys.platform.startswith("win"):
|
||||
try:
|
||||
with open(os.devnull, "wb") as devnull:
|
||||
subprocess.check_call(["gs", "--version"], stdout=devnull)
|
||||
subprocess.check_call(["gs", "--version"], stdout=subprocess.DEVNULL)
|
||||
return True
|
||||
except OSError:
|
||||
# No Ghostscript
|
||||
|
|
|
@ -623,20 +623,20 @@ def _save_netpbm(im, fp, filename):
|
|||
|
||||
with open(filename, "wb") as f:
|
||||
if im.mode != "RGB":
|
||||
with open(os.devnull, "wb") as devnull:
|
||||
subprocess.check_call(["ppmtogif", tempfile], stdout=f, stderr=devnull)
|
||||
subprocess.check_call(
|
||||
["ppmtogif", tempfile], stdout=f, stderr=subprocess.DEVNULL
|
||||
)
|
||||
else:
|
||||
# Pipe ppmquant output into ppmtogif
|
||||
# "ppmquant 256 %s | ppmtogif > %s" % (tempfile, filename)
|
||||
quant_cmd = ["ppmquant", "256", tempfile]
|
||||
togif_cmd = ["ppmtogif"]
|
||||
with open(os.devnull, "wb") as devnull:
|
||||
quant_proc = subprocess.Popen(
|
||||
quant_cmd, stdout=subprocess.PIPE, stderr=devnull
|
||||
)
|
||||
togif_proc = subprocess.Popen(
|
||||
togif_cmd, stdin=quant_proc.stdout, stdout=f, stderr=devnull
|
||||
)
|
||||
quant_proc = subprocess.Popen(
|
||||
quant_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
|
||||
)
|
||||
togif_proc = subprocess.Popen(
|
||||
togif_cmd, stdin=quant_proc.stdout, stdout=f, stderr=subprocess.DEVNULL
|
||||
)
|
||||
|
||||
# Allow ppmquant to receive SIGPIPE if ppmtogif exits
|
||||
quant_proc.stdout.close()
|
||||
|
|
|
@ -336,10 +336,9 @@ def _save(im, fp, filename):
|
|||
# iconutil -c icns -o {} {}
|
||||
|
||||
convert_cmd = ["iconutil", "-c", "icns", "-o", filename, iconset]
|
||||
with open(os.devnull, "wb") as devnull:
|
||||
convert_proc = subprocess.Popen(
|
||||
convert_cmd, stdout=subprocess.PIPE, stderr=devnull
|
||||
)
|
||||
convert_proc = subprocess.Popen(
|
||||
convert_cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
|
||||
)
|
||||
|
||||
convert_proc.stdout.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user