Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1178983

Browse files
authored
Merge pull request #22423 from anntzer/xpdf
Avoid indiscriminate glob-remove in xpdf_distill.
2 parents 88fc75c + 93bf35d commit 1178983

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import datetime
77
from enum import Enum
88
import functools
9-
import glob
109
from io import StringIO
1110
import logging
1211
import math
@@ -1214,32 +1213,26 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
12141213
mpl._get_executable_info("gs") # Effectively checks for ps2pdf.
12151214
mpl._get_executable_info("pdftops")
12161215

1217-
pdffile = tmpfile + '.pdf'
1218-
psfile = tmpfile + '.ps'
1219-
1220-
# Pass options as `-foo#bar` instead of `-foo=bar` to keep Windows happy
1221-
# (https://www.ghostscript.com/doc/9.22/Use.htm#MS_Windows).
1222-
cbook._check_and_log_subprocess(
1223-
["ps2pdf",
1224-
"-dAutoFilterColorImages#false",
1225-
"-dAutoFilterGrayImages#false",
1226-
"-sAutoRotatePages#None",
1227-
"-sGrayImageFilter#FlateEncode",
1228-
"-sColorImageFilter#FlateEncode",
1229-
"-dEPSCrop" if eps else "-sPAPERSIZE#%s" % ptype,
1230-
tmpfile, pdffile], _log)
1231-
cbook._check_and_log_subprocess(
1232-
["pdftops", "-paper", "match", "-level2", pdffile, psfile], _log)
1233-
1234-
os.remove(tmpfile)
1235-
shutil.move(psfile, tmpfile)
1236-
1216+
with TemporaryDirectory() as tmpdir:
1217+
tmppdf = pathlib.Path(tmpdir, "tmp.pdf")
1218+
tmpps = pathlib.Path(tmpdir, "tmp.ps")
1219+
# Pass options as `-foo#bar` instead of `-foo=bar` to keep Windows
1220+
# happy (https://www.ghostscript.com/doc/9.22/Use.htm#MS_Windows).
1221+
cbook._check_and_log_subprocess(
1222+
["ps2pdf",
1223+
"-dAutoFilterColorImages#false",
1224+
"-dAutoFilterGrayImages#false",
1225+
"-sAutoRotatePages#None",
1226+
"-sGrayImageFilter#FlateEncode",
1227+
"-sColorImageFilter#FlateEncode",
1228+
"-dEPSCrop" if eps else "-sPAPERSIZE#%s" % ptype,
1229+
tmpfile, tmppdf], _log)
1230+
cbook._check_and_log_subprocess(
1231+
["pdftops", "-paper", "match", "-level2", tmppdf, tmpps], _log)
1232+
shutil.move(tmpps, tmpfile)
12371233
if eps:
12381234
pstoeps(tmpfile)
12391235

1240-
for fname in glob.glob(tmpfile+'.*'):
1241-
os.remove(fname)
1242-
12431236

12441237
def get_bbox_header(lbrt, rotated=False):
12451238
"""

0 commit comments

Comments
 (0)