Skip to content

Commit e75ad10

Browse files
committed
add a tagline mentioning the paperbackup.py url to the plaintext part
also change from os.system() to subprocess
1 parent 9501f04 commit e75ad10

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

paperbackup.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import os
3131
import re
3232
import sys
33-
import shlex
33+
import subprocess
3434
import qrencode
3535
from tempfile import mkstemp
3636
from PIL import Image
@@ -135,19 +135,32 @@ def finish_page(pdf, canv, pageno):
135135
# will use pdf as the tmpfile has a .pdf suffix
136136
pdf.writetofile(temp_barcode_path)
137137

138-
# use "enscript" to create postscript with the plaintext
139138
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:
144157
raise RuntimeError('error calling enscript')
145158

146159
# 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])
151164
if ret != 0:
152165
raise RuntimeError('error calling ghostscript')
153166

0 commit comments

Comments
 (0)