|
8 | 8 | import six
|
9 | 9 | from six.moves import StringIO
|
10 | 10 |
|
11 |
| -import glob, math, os, shutil, sys, time |
| 11 | +import glob, math, os, shutil, sys, subprocess, time |
12 | 12 | def _fn_name(): return sys._getframe(1).f_code.co_name
|
13 | 13 | import io
|
14 | 14 |
|
@@ -1424,23 +1424,26 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
|
1424 | 1424 | command = '%s cd "%s" && latex -interaction=nonstopmode "%s" > "%s"'\
|
1425 | 1425 | %(precmd, tmpdir, latexfile, outfile)
|
1426 | 1426 | verbose.report(command, 'debug')
|
1427 |
| - exit_status = os.system(command) |
1428 |
| - |
1429 | 1427 | with io.open(outfile, 'rb') as fh:
|
1430 |
| - if exit_status: |
| 1428 | + try: |
| 1429 | + output = subprocess.check_output(command, shell=True, |
| 1430 | + stderr=subprocess.STDOUT) |
| 1431 | + except subprocess.CalledProcessError as exc: |
1431 | 1432 | raise RuntimeError('LaTeX was not able to process your file:\
|
1432 |
| - \nHere is the full report generated by LaTeX: \n\n%s'% fh.read()) |
| 1433 | +and failed with %s.\n\ |
| 1434 | + \nHere is the full report generated by LaTeX: \n\n%s'% (output, fh.read())) |
1433 | 1435 | else:
|
1434 | 1436 | verbose.report(fh.read(), 'debug')
|
1435 | 1437 | os.remove(outfile)
|
1436 | 1438 |
|
1437 | 1439 | command = '%s cd "%s" && dvips -q -R0 -o "%s" "%s" > "%s"'%(precmd, tmpdir,
|
1438 | 1440 | os.path.split(psfile)[-1], os.path.split(dvifile)[-1], outfile)
|
1439 | 1441 | verbose.report(command, 'debug')
|
1440 |
| - exit_status = os.system(command) |
1441 |
| - |
1442 | 1442 | with io.open(outfile, 'rb') as fh:
|
1443 |
| - if exit_status: |
| 1443 | + try: |
| 1444 | + output = subprocess.check_output(command, shell=True, |
| 1445 | + stderr=subprocess.STDOUT) |
| 1446 | + except subprocess.CalledProcessError as exc: |
1444 | 1447 | raise RuntimeError('dvips was not able to \
|
1445 | 1448 | process the following file:\n%s\nHere is the full report generated by dvips: \
|
1446 | 1449 | \n\n'% dvifile + fh.read())
|
@@ -1495,17 +1498,30 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
|
1495 | 1498 | paper_option, psfile, tmpfile, outfile)
|
1496 | 1499 |
|
1497 | 1500 | verbose.report(command, 'debug')
|
1498 |
| - exit_status = os.system(command) |
| 1501 | + with io.open(outfile, 'rb') as fh: |
| 1502 | + try: |
| 1503 | + output = subprocess.check_output(command, shell=True, |
| 1504 | + stderr=subprocess.STDOUT) |
| 1505 | + except subprocess.CalledProcessError as exc: |
| 1506 | + raise RuntimeError('dvips was not able to \ |
| 1507 | + process the following file:\n%s\nHere is the full report generated by dvips: \ |
| 1508 | + \n\n'% dvifile + fh.read()) |
| 1509 | + else: |
| 1510 | + verbose.report(fh.read(), 'debug') |
1499 | 1511 |
|
1500 | 1512 | with io.open(outfile, 'rb') as fh:
|
1501 |
| - if exit_status: |
| 1513 | + try: |
| 1514 | + process_output = subprocess.check_output(command, shell=True, |
| 1515 | + stderr=subprocess.STDOUT) |
| 1516 | + except subprocess.CalledProcessError as exc: |
1502 | 1517 | output = fh.read()
|
1503 | 1518 | m = "\n".join(["ghostscript was not able to process your image.",
|
| 1519 | + "It failed with %s.", |
1504 | 1520 | "Here is the full report generated by ghostscript:",
|
1505 | 1521 | "",
|
1506 | 1522 | "%s"])
|
1507 | 1523 | # use % to prevent problems with bytes
|
1508 |
| - raise RuntimeError(m % output) |
| 1524 | + raise RuntimeError(m % (process_output, output)) |
1509 | 1525 | else:
|
1510 | 1526 | verbose.report(fh.read(), 'debug')
|
1511 | 1527 | os.remove(outfile)
|
@@ -1548,23 +1564,28 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
|
1548 | 1564 | (paper_option, tmpfile, pdffile, outfile)
|
1549 | 1565 | if sys.platform == 'win32': command = command.replace('=', '#')
|
1550 | 1566 | verbose.report(command, 'debug')
|
1551 |
| - exit_status = os.system(command) |
| 1567 | + |
1552 | 1568 | with io.open(outfile, 'rb') as fh:
|
1553 |
| - if exit_status: |
| 1569 | + try: |
| 1570 | + output = subprocess.check_output(command, shell=True, |
| 1571 | + stderr=subprocess.STDOUT) |
| 1572 | + except subprocess.CalledProcessError as exc: |
1554 | 1573 | raise RuntimeError('ps2pdf was not able to process your \
|
1555 |
| -image.\n\Here is the report generated by ghostscript:\n\n' + fh.read()) |
| 1574 | +image and failed with %s.\n\Here is the report generated by ghostscript:\n\n' % (output) + fh.read()) |
1556 | 1575 | else:
|
1557 | 1576 | verbose.report(fh.read(), 'debug')
|
1558 | 1577 | os.remove(outfile)
|
1559 | 1578 | command = 'pdftops -paper match -level2 "%s" "%s" > "%s"'% \
|
1560 | 1579 | (pdffile, psfile, outfile)
|
1561 | 1580 | verbose.report(command, 'debug')
|
1562 |
| - exit_status = os.system(command) |
1563 | 1581 |
|
1564 | 1582 | with io.open(outfile, 'rb') as fh:
|
1565 |
| - if exit_status: |
| 1583 | + try: |
| 1584 | + output = subprocess.check_output(command, shell=True, |
| 1585 | + stderr=subprocess.STDOUT) |
| 1586 | + except subprocess.CalledProcessError as exc: |
1566 | 1587 | raise RuntimeError('pdftops was not able to process your \
|
1567 |
| -image.\nHere is the full report generated by pdftops: \n\n' + fh.read()) |
| 1588 | +image and failed with %s.\nHere is the full report generated by pdftops: \n\n' % (output) + fh.read()) |
1568 | 1589 | else:
|
1569 | 1590 | verbose.report(fh.read(), 'debug')
|
1570 | 1591 | os.remove(outfile)
|
|
0 commit comments