mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
Change most uses of os.system to use subprocess
The only places left that use os.system are in ImageShow and setup.py
This commit is contained in:
parent
d283f77884
commit
34317edd8a
|
@ -333,13 +333,20 @@ def _save_netpbm(im, fp, filename):
|
|||
# below for information on how to enable this.
|
||||
|
||||
import os
|
||||
from subprocess import Popen, check_call, PIPE
|
||||
file = im._dump()
|
||||
if im.mode != "RGB":
|
||||
os.system("ppmtogif %s >%s" % (file, filename))
|
||||
with open(filename, 'wb') as f:
|
||||
check_call(["ppmtogif", file], stdout=f)
|
||||
else:
|
||||
os.system("ppmquant 256 %s | ppmtogif >%s" % (file, filename))
|
||||
try: os.unlink(file)
|
||||
except: pass
|
||||
with open(filename, 'wb') as f:
|
||||
#TODO: What happens if ppmquant fails?
|
||||
ppmquant_proc = Popen(["ppmquant", "256", file], stdout=PIPE)
|
||||
check_call(["ppmtogif"], stdin=ppmquant_proc.stdout, stdout=f)
|
||||
try:
|
||||
os.unlink(file)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
|
|
@ -360,12 +360,14 @@ class JpegImageFile(ImageFile.ImageFile):
|
|||
|
||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
||||
|
||||
import subprocess
|
||||
import tempfile
|
||||
import os
|
||||
f, path = tempfile.mkstemp()
|
||||
os.close(f)
|
||||
if os.path.exists(self.filename):
|
||||
os.system("djpeg %s > '%s'" % (quote(self.filename), path))
|
||||
with open(path, 'wb') as f:
|
||||
subprocess.check_call(["djpeg", self.filename], stdout=f)
|
||||
else:
|
||||
raise ValueError("Invalid Filename")
|
||||
|
||||
|
@ -608,8 +610,10 @@ def _save(im, fp, filename):
|
|||
def _save_cjpeg(im, fp, filename):
|
||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities.
|
||||
import os
|
||||
file = im._dump()
|
||||
os.system("cjpeg %s >%s" % (file, filename))
|
||||
import subprocess
|
||||
tempfile = im._dump()
|
||||
with open(filename, 'wb') as f:
|
||||
subprocess.check_call(["cjpeg", tempfile], stdout=f)
|
||||
try:
|
||||
os.unlink(file)
|
||||
except:
|
||||
|
|
Loading…
Reference in New Issue
Block a user