|
30 | 30 | import os
|
31 | 31 | import re
|
32 | 32 | import sys
|
33 |
| -import shlex |
| 33 | +import subprocess |
34 | 34 | import qrencode
|
35 | 35 | from tempfile import mkstemp
|
36 | 36 | from PIL import Image
|
@@ -135,19 +135,32 @@ def finish_page(pdf, canv, pageno):
|
135 | 135 | # will use pdf as the tmpfile has a .pdf suffix
|
136 | 136 | pdf.writetofile(temp_barcode_path)
|
137 | 137 |
|
138 |
| -# use "enscript" to create postscript with the plaintext |
139 | 138 | fd, temp_text_path = mkstemp('.ps', 'text_', '.')
|
140 |
| -ret = os.system("enscript -p" + shlex.quote(temp_text_path) + |
141 |
| - " -f Courier12 -M" + paperformat_str + |
142 |
| - " " + shlex.quote(input_path)) |
143 |
| -if ret != 0: |
| 139 | + |
| 140 | +# use "enscript" to create postscript with the plaintext |
| 141 | +p = subprocess.Popen( |
| 142 | + ["enscript", "-p"+temp_text_path, "-f", "Courier12", |
| 143 | + "-M" + paperformat_str, "--header", |
| 144 | + just_filename + "|Page $%"], |
| 145 | + stdout=subprocess.PIPE,stdin=subprocess.PIPE) |
| 146 | + |
| 147 | +# send the file and a tag line to enscript |
| 148 | +p.stdin.write(ascdata.encode('utf-8')) |
| 149 | +p.stdin.write("\n\n\n--\n".encode('utf-8')) |
| 150 | +p.stdin.write("Created with paperbackup.py\n".encode('utf-8')) |
| 151 | +p.stdin.write("See https://github.com/intra2net/paperbackup/ for instructions\n".encode('utf-8')) |
| 152 | + |
| 153 | +p.communicate()[0] |
| 154 | +p.stdin.close() |
| 155 | + |
| 156 | +if p.returncode != 0: |
144 | 157 | raise RuntimeError('error calling enscript')
|
145 | 158 |
|
146 | 159 | # combine both files with ghostscript
|
147 |
| -ret = os.system("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" + |
148 |
| - shlex.quote(just_filename) + |
149 |
| - ".pdf " + shlex.quote(temp_barcode_path) + " " + |
150 |
| - shlex.quote(temp_text_path)) |
| 160 | + |
| 161 | +ret = subprocess.call(["gs", "-dBATCH", "-dNOPAUSE", "-q", "-sDEVICE=pdfwrite", |
| 162 | + "-sOutputFile=" + just_filename + ".pdf", |
| 163 | + temp_barcode_path, temp_text_path]) |
151 | 164 | if ret != 0:
|
152 | 165 | raise RuntimeError('error calling ghostscript')
|
153 | 166 |
|
|
0 commit comments