From 731c307562a0e3a4fb25c4b52bc44eb69058c943 Mon Sep 17 00:00:00 2001 From: Dmitriy Shesterkin Date: Tue, 2 May 2017 23:11:50 +0300 Subject: [PATCH] add try in subprocess pdf to png --- src/docs/views/base_views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/docs/views/base_views.py b/src/docs/views/base_views.py index 3b46e3d..c3c0ce8 100644 --- a/src/docs/views/base_views.py +++ b/src/docs/views/base_views.py @@ -6,6 +6,7 @@ import tempfile from email.header import Header from time import time import simplejson as json +import sys import subprocess as s from django.contrib import messages from django.db import DatabaseError @@ -418,10 +419,12 @@ class BaseViews(object): "-sOutputFile=%s" % os.path.join(tmp_dir, "page-%03d.png"), "-f", filename ] - - p = s.Popen(args=args, stdout=s.PIPE, stderr=s.PIPE) - # # ghostscript.Ghostscript(*args) # TODO: check on ubuntu - p.wait() + # ghostscript.Ghostscript(*args) # TODO: check on ubuntu + try: + p = s.Popen(args=args, stdout=s.PIPE, stderr=s.PIPE) + p.wait() + except OSError: + sys.exit("Error executing Ghostscript. Is it in your PATH?") os.remove(filename) filename = '%s.pdf' % self.get_filename(*args, **kwargs) imgs = glob.glob(os.path.join(tmp_dir, '*.png'))