| Total Complexity | 0 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import os |
||
| 2 | import shutil |
||
| 3 | import sys |
||
| 4 | import logging |
||
| 5 | |||
| 6 | logging.basicConfig(level=logging.DEBUG) |
||
| 7 | logger = logging.getLogger('FuzzEd') |
||
| 8 | |||
| 9 | # Determine parameters from command line |
||
| 10 | if len(sys.argv) != 6: |
||
| 11 | logger.error('%s [--eps|--pdf] <working_dir> <input file> <output file> <log file>'%sys.argv[0]) |
||
| 12 | exit(-1) |
||
| 13 | kind = sys.argv[1][2:] |
||
| 14 | working_dir = sys.argv[4] |
||
| 15 | input_fname = sys.argv[2] |
||
| 16 | output_fname = sys.argv[3] |
||
| 17 | |||
| 18 | # Only needed for Ubuntu 12.10, all others have it as part of the installation |
||
| 19 | shutil.copy("rendering/adjustbox.sty", working_dir) |
||
| 20 | shutil.copy("rendering/collectbox.sty", working_dir) |
||
| 21 | shutil.copy("rendering/adjgrfx.sty", working_dir) |
||
| 22 | |||
| 23 | # Latex cannot operate well on files in another directory, so we go there directly |
||
| 24 | # This is anyway epxected to be the temporary job execution directory created by the daemon |
||
| 25 | olddir = os.getcwd() |
||
| 26 | os.chdir(working_dir) |
||
| 27 | os.rename(input_fname, 'graph.tex') |
||
| 28 | exit_code = -1 |
||
| 29 | if kind == 'eps': |
||
| 30 | os.system("latex -interaction nonstopmode graph.tex") |
||
| 31 | if os.path.exists('graph.dvi'): |
||
| 32 | os.system("dvips graph") |
||
| 33 | os.system("ps2eps -R + -f -a graph.ps") |
||
| 34 | os.rename('graph.eps', output_fname) |
||
| 35 | exit_code = 0 |
||
| 36 | elif kind == 'pdf': |
||
| 37 | os.system("pdflatex -interaction nonstopmode graph.tex") |
||
| 38 | if os.path.exists('graph.pdf'): |
||
| 39 | os.rename('graph.pdf', output_fname) |
||
| 40 | exit_code = 0 |
||
| 41 | |||
| 42 | os.chdir(olddir) |
||
| 43 | exit(exit_code) |