@@ -1421,34 +1421,13 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
14211421 latexfile = latexfile .replace ("\\ " , "/" )
14221422 # Replace ~ so Latex does not think it is line break
14231423 latexfile = latexfile .replace ("~" , "\\ string~" )
1424- command = ["latex" , "-interaction=nonstopmode" , '"%s"' % latexfile ]
1425- _log .debug ('%s' , command )
1426- try :
1427- report = subprocess .check_output (command , cwd = tmpdir ,
1428- stderr = subprocess .STDOUT )
1429- except subprocess .CalledProcessError as exc :
1430- raise RuntimeError (
1431- ('LaTeX was not able to process the following '
1432- 'file:\n %s\n \n '
1433- 'Here is the full report generated by LaTeX:\n %s '
1434- '\n \n ' % (latexfile ,
1435- exc .output .decode ("utf-8" ))))
1436- _log .debug (report )
1437-
1438- command = ['dvips' , '-q' , '-R0' , '-o' , os .path .basename (psfile ),
1439- os .path .basename (dvifile )]
1440- _log .debug (command )
1441- try :
1442- report = subprocess .check_output (command , cwd = tmpdir ,
1443- stderr = subprocess .STDOUT )
1444- except subprocess .CalledProcessError as exc :
1445- raise RuntimeError (
1446- ('dvips was not able to process the following '
1447- 'file:\n %s\n \n '
1448- 'Here is the full report generated by dvips:\n %s '
1449- '\n \n ' % (dvifile ,
1450- exc .output .decode ("utf-8" ))))
1451- _log .debug (report )
1424+
1425+ cbook ._check_and_log_subprocess (
1426+ ["latex" , "-interaction=nonstopmode" , '"%s"' % latexfile ],
1427+ _log , cwd = tmpdir )
1428+ cbook ._check_and_log_subprocess (
1429+ ['dvips' , '-q' , '-R0' , '-o' , os .path .basename (psfile ),
1430+ os .path .basename (dvifile )], _log , cwd = tmpdir )
14521431 os .remove (epsfile )
14531432 shutil .move (psfile , tmpfile )
14541433
@@ -1493,18 +1472,11 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
14931472 else :
14941473 device_name = "pswrite"
14951474
1496- command = [str (gs_exe ), "-dBATCH" , "-dNOPAUSE" , "-r%d" % dpi ,
1497- "-sDEVICE=%s" % device_name , paper_option ,
1498- "-sOutputFile=%s" % psfile , tmpfile ]
1499- _log .debug (command )
1500- try :
1501- report = subprocess .check_output (command , stderr = subprocess .STDOUT )
1502- except subprocess .CalledProcessError as exc :
1503- raise RuntimeError (
1504- ('ghostscript was not able to process your image.\n '
1505- 'Here is the full report generated by ghostscript:\n %s '
1506- '\n \n ' % exc .output .decode ("utf-8" )))
1507- _log .debug (report )
1475+ cbook ._check_and_log_subprocess (
1476+ [gs_exe , "-dBATCH" , "-dNOPAUSE" , "-r%d" % dpi ,
1477+ "-sDEVICE=%s" % device_name , paper_option ,
1478+ "-sOutputFile=%s" % psfile , tmpfile ], _log )
1479+
15081480 os .remove (tmpfile )
15091481 shutil .move (psfile , tmpfile )
15101482
@@ -1535,35 +1507,18 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15351507
15361508 # Pass options as `-foo#bar` instead of `-foo=bar` to keep Windows happy
15371509 # (https://www.ghostscript.com/doc/9.22/Use.htm#MS_Windows).
1538- command = ["ps2pdf" ,
1539- "-dAutoFilterColorImages#false" ,
1540- "-dAutoFilterGrayImages#false" ,
1541- "-dAutoRotatePages#false" ,
1542- "-sGrayImageFilter#FlateEncode" ,
1543- "-sColorImageFilter#FlateEncode" ,
1544- "-dEPSCrop" if eps else "-sPAPERSIZE#%s" % ptype ,
1545- tmpfile , pdffile ]
1546- _log .debug (command )
1547-
1548- try :
1549- report = subprocess .check_output (command , stderr = subprocess .STDOUT )
1550- except subprocess .CalledProcessError as exc :
1551- raise RuntimeError (
1552- ('ps2pdf was not able to process your image.\n '
1553- 'Here is the full report generated by ps2pdf:\n %s '
1554- '\n \n ' % exc .output .decode ("utf-8" )))
1555- _log .debug (report )
1510+ cbook ._check_and_log_subprocess (
1511+ ["ps2pdf" ,
1512+ "-dAutoFilterColorImages#false" ,
1513+ "-dAutoFilterGrayImages#false" ,
1514+ "-dAutoRotatePages#false" ,
1515+ "-sGrayImageFilter#FlateEncode" ,
1516+ "-sColorImageFilter#FlateEncode" ,
1517+ "-dEPSCrop" if eps else "-sPAPERSIZE#%s" % ptype ,
1518+ tmpfile , pdffile ], _log )
1519+ cbook ._check_and_log_subprocess (
1520+ ["pdftops" , "-paper" , "match" , "-level2" , pdffile , psfile ], _log )
15561521
1557- command = ["pdftops" , "-paper" , "match" , "-level2" , pdffile , psfile ]
1558- _log .debug (command )
1559- try :
1560- report = subprocess .check_output (command , stderr = subprocess .STDOUT )
1561- except subprocess .CalledProcessError as exc :
1562- raise RuntimeError (
1563- ('pdftops was not able to process your image.\n '
1564- 'Here is the full report generated by pdftops:\n %s '
1565- '\n \n ' % exc .output .decode ("utf-8" )))
1566- _log .debug (report )
15671522 os .remove (tmpfile )
15681523 shutil .move (psfile , tmpfile )
15691524
0 commit comments