Skip to content

Commit 3604e68

Browse files
committed
merge-pdfs: Check executables.
1 parent 236a9db commit 3604e68

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎python3/merge-pdfs-printable.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
import subprocess
1010
import tempfile
1111

12+
# Make sure executables are in PATH.
13+
executables_used = ['ps2pdf', 'gs', 'pdfinfo']
14+
def exe_exists(program):
15+
def is_exe(fpath): return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
16+
for path in os.environ["PATH"].split(os.pathsep):
17+
path = path.strip('"')
18+
exe_file = os.path.join(path, program)
19+
if is_exe(exe_file): return
20+
raise Exception("Unable to find program on PATH: '{}'.".format(program))
21+
[exe_exists(e) for e in executables_used]
22+
1223
def create_blank_pdf(f_path):
1324
with open(f_path, 'w'):
1425
os.utime(f_path)

0 commit comments

Comments
 (0)