From 51f1453917530fef37ab08cd6e48216b1c9f3fe6 Mon Sep 17 00:00:00 2001 From: Cervinko Cera Date: Fri, 8 Apr 2016 22:57:16 +0200 Subject: [PATCH] check if wand is available, add dummy cover.jpg otherwise --- cps/web.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cps/web.py b/cps/web.py index 97bfa751..bce91a84 100755 --- a/cps/web.py +++ b/cps/web.py @@ -21,9 +21,14 @@ from functools import wraps import base64 from sqlalchemy.sql import * import json -from wand.image import Image import datetime from uuid import uuid4 +try: + from wand.image import Image + use_generic_pdf_cover = False +except ImportError, e: + use_generic_pdf_cover = True +from shutil import copyfile app = (Flask(__name__)) @@ -776,10 +781,15 @@ def upload(): file_size = os.path.getsize(saved_filename) has_cover = 0 if fileextension.upper() == ".PDF": - with Image(filename=saved_filename + "[0]", resolution=150) as img: - img.compression_quality = 88 - img.save(filename=os.path.join(filepath, "cover.jpg")) - has_cover = 1 + if use_generic_pdf_cover: + basedir = os.path.dirname(__file__) + print basedir + copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg")) + else: + with Image(filename=saved_filename + "[0]", resolution=150) as img: + img.compression_quality = 88 + img.save(filename=os.path.join(filepath, "cover.jpg")) + has_cover = 1 is_author = db.session.query(db.Authors).filter(db.Authors.name == author).first() if is_author: db_author = is_author