Raise error if ghostscript not installed

pull/198/head
Vinayak Mehta 2021-06-28 02:20:44 +05:30
parent 4cebd684ba
commit a96702987f
No known key found for this signature in database
GPG Key ID: 2DE013537A15A9A4
1 changed files with 30 additions and 0 deletions

View File

@ -1,10 +1,40 @@
# -*- coding: utf-8 -*-
import sys
import ctypes
from ctypes.util import find_library
import ghostscript
def installed_posix():
library = find_library("gs")
return library is not None
def installed_windows():
library = find_library(
"".join(("gsdll", str(ctypes.sizeof(ctypes.c_voidp) * 8), ".dll"))
)
return library is not None
class GhostscriptBackend(object):
def installed(self):
if sys.platform in ["linux", "darwin"]:
return installed_posix()
elif sys.platform == "win32":
return installed_windows()
else:
return installed_posix()
def convert(self, pdf_path, png_path, resolution=300):
if not self.installed():
raise OSError(
"Ghostscript is not installed. Please install it using the instructions"
"here: https://camelot-py.readthedocs.io/en/master/user/install-deps.html"
)
gs_args = [
"gs",
"-q",