|
8 | 8 | import six
|
9 | 9 | from six.moves import StringIO
|
10 | 10 |
|
11 |
| -import glob, math, os, shutil, sys, time, datetime |
| 11 | +import glob, math, os, shutil, sys, subprocess, time, datetime |
12 | 12 | def _fn_name(): return sys._getframe(1).f_code.co_name
|
13 | 13 | import io
|
14 | 14 |
|
@@ -1440,27 +1440,32 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
|
1440 | 1440 | command = '%s cd "%s" && latex -interaction=nonstopmode "%s" > "%s"'\
|
1441 | 1441 | %(precmd, tmpdir, latexfile, outfile)
|
1442 | 1442 | verbose.report(command, 'debug')
|
1443 |
| - exit_status = os.system(command) |
1444 |
| - |
1445 |
| - with io.open(outfile, 'rb') as fh: |
1446 |
| - if exit_status: |
| 1443 | + try: |
| 1444 | + output = subprocess.check_output(command, shell=True, |
| 1445 | + stderr=subprocess.STDOUT) |
| 1446 | + except subprocess.CalledProcessError as exc: |
| 1447 | + with io.open(outfile, 'rb') as fh: |
1447 | 1448 | raise RuntimeError('LaTeX was not able to process your file:\
|
1448 |
| - \nHere is the full report generated by LaTeX: \n\n%s'% fh.read()) |
1449 |
| - else: |
| 1449 | +and failed with %s.\n\ |
| 1450 | +\nHere is the full report generated by LaTeX: \n\n%s'% (output, fh.read())) |
| 1451 | + else: |
| 1452 | + with io.open(outfile, 'rb') as fh: |
1450 | 1453 | verbose.report(fh.read(), 'debug')
|
1451 | 1454 | os.remove(outfile)
|
1452 | 1455 |
|
1453 | 1456 | command = '%s cd "%s" && dvips -q -R0 -o "%s" "%s" > "%s"'%(precmd, tmpdir,
|
1454 | 1457 | os.path.split(psfile)[-1], os.path.split(dvifile)[-1], outfile)
|
1455 | 1458 | verbose.report(command, 'debug')
|
1456 |
| - exit_status = os.system(command) |
1457 |
| - |
1458 |
| - with io.open(outfile, 'rb') as fh: |
1459 |
| - if exit_status: |
| 1459 | + try: |
| 1460 | + output = subprocess.check_output(command, shell=True, |
| 1461 | + stderr=subprocess.STDOUT) |
| 1462 | + except subprocess.CalledProcessError as exc: |
| 1463 | + with io.open(outfile, 'rb') as fh: |
1460 | 1464 | raise RuntimeError('dvips was not able to \
|
1461 |
| - process the following file:\n%s\nHere is the full report generated by dvips: \ |
1462 |
| - \n\n'% dvifile + fh.read()) |
1463 |
| - else: |
| 1465 | +process the following file:\n%s\nHere is the full report generated by dvips: \ |
| 1466 | +\n\n'% dvifile + fh.read()) |
| 1467 | + else: |
| 1468 | + with io.open(outfile, 'rb') as fh: |
1464 | 1469 | verbose.report(fh.read(), 'debug')
|
1465 | 1470 | os.remove(outfile)
|
1466 | 1471 | os.remove(epsfile)
|
@@ -1511,19 +1516,34 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
|
1511 | 1516 | paper_option, psfile, tmpfile, outfile)
|
1512 | 1517 |
|
1513 | 1518 | verbose.report(command, 'debug')
|
1514 |
| - exit_status = os.system(command) |
1515 |
| - |
1516 |
| - with io.open(outfile, 'rb') as fh: |
1517 |
| - if exit_status: |
1518 |
| - output = fh.read() |
1519 |
| - m = "\n".join(["ghostscript was not able to process your image.", |
1520 |
| - "Here is the full report generated by ghostscript:", |
1521 |
| - "", |
1522 |
| - "%s"]) |
1523 |
| - # use % to prevent problems with bytes |
1524 |
| - raise RuntimeError(m % output) |
1525 |
| - else: |
| 1519 | + try: |
| 1520 | + output = subprocess.check_output(command, shell=True, |
| 1521 | + stderr=subprocess.STDOUT) |
| 1522 | + except subprocess.CalledProcessError as exc: |
| 1523 | + with io.open(outfile, 'rb') as fh: |
| 1524 | + raise RuntimeError('dvips was not able to \ |
| 1525 | +process the following file:\n%s\nHere is the full report generated by dvips: \ |
| 1526 | +\n\n'% dvifile + fh.read()) |
| 1527 | + else: |
| 1528 | + with io.open(outfile, 'rb') as fh: |
1526 | 1529 | verbose.report(fh.read(), 'debug')
|
| 1530 | + |
| 1531 | + try: |
| 1532 | + process_output = subprocess.check_output(command, shell=True, |
| 1533 | + stderr=subprocess.STDOUT) |
| 1534 | + except subprocess.CalledProcessError as exc: |
| 1535 | + with io.open(outfile, 'rb') as fh: |
| 1536 | + output = fh.read() |
| 1537 | + m = "\n".join(["ghostscript was not able to process your image.", |
| 1538 | + "It failed with %s.", |
| 1539 | + "Here is the full report generated by ghostscript:", |
| 1540 | + "", |
| 1541 | + "%s"]) |
| 1542 | + # use % to prevent problems with bytes |
| 1543 | + raise RuntimeError(m % (process_output, output)) |
| 1544 | + else: |
| 1545 | + with io.open(outfile, 'rb') as fh: |
| 1546 | + verbose.report(fh.read(), 'debug') |
1527 | 1547 | os.remove(outfile)
|
1528 | 1548 | os.remove(tmpfile)
|
1529 | 1549 | shutil.move(psfile, tmpfile)
|
@@ -1564,24 +1584,31 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
|
1564 | 1584 | (paper_option, tmpfile, pdffile, outfile)
|
1565 | 1585 | if sys.platform == 'win32': command = command.replace('=', '#')
|
1566 | 1586 | verbose.report(command, 'debug')
|
1567 |
| - exit_status = os.system(command) |
1568 |
| - with io.open(outfile, 'rb') as fh: |
1569 |
| - if exit_status: |
| 1587 | + |
| 1588 | + try: |
| 1589 | + output = subprocess.check_output(command, shell=True, |
| 1590 | + stderr=subprocess.STDOUT) |
| 1591 | + except subprocess.CalledProcessError as exc: |
| 1592 | + with io.open(outfile, 'rb') as fh: |
1570 | 1593 | raise RuntimeError('ps2pdf was not able to process your \
|
1571 |
| -image.\n\Here is the report generated by ghostscript:\n\n' + fh.read()) |
1572 |
| - else: |
| 1594 | +image and failed with %s.\n\Here is the report generated by ghostscript:\n\n' % (output) + fh.read()) |
| 1595 | + else: |
| 1596 | + with io.open(outfile, 'rb') as fh: |
1573 | 1597 | verbose.report(fh.read(), 'debug')
|
1574 | 1598 | os.remove(outfile)
|
1575 | 1599 | command = 'pdftops -paper match -level2 "%s" "%s" > "%s"'% \
|
1576 | 1600 | (pdffile, psfile, outfile)
|
1577 | 1601 | verbose.report(command, 'debug')
|
1578 |
| - exit_status = os.system(command) |
1579 | 1602 |
|
1580 |
| - with io.open(outfile, 'rb') as fh: |
1581 |
| - if exit_status: |
| 1603 | + try: |
| 1604 | + output = subprocess.check_output(command, shell=True, |
| 1605 | + stderr=subprocess.STDOUT) |
| 1606 | + except subprocess.CalledProcessError as exc: |
| 1607 | + with io.open(outfile, 'rb') as fh: |
1582 | 1608 | raise RuntimeError('pdftops was not able to process your \
|
1583 |
| -image.\nHere is the full report generated by pdftops: \n\n' + fh.read()) |
1584 |
| - else: |
| 1609 | +image and failed with %s.\nHere is the full report generated by pdftops: \n\n' % (output) + fh.read()) |
| 1610 | + else: |
| 1611 | + with io.open(outfile, 'rb') as fh: |
1585 | 1612 | verbose.report(fh.read(), 'debug')
|
1586 | 1613 | os.remove(outfile)
|
1587 | 1614 | os.remove(tmpfile)
|
|
0 commit comments