From: Jan Szejko Date: Tue, 27 Dec 2016 11:12:33 +0000 (+0100) Subject: error reporting X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/1428a9d8f91b754fe7f9fb96cbdd0d6a2536ffc1?ds=sidebyside;hp=5135e076096ce04b1dbbb2f6210512d1a44fa237 error reporting --- diff --git a/librarian/formats/cover/__init__.py b/librarian/formats/cover/__init__.py index d410058..4788e39 100644 --- a/librarian/formats/cover/__init__.py +++ b/librarian/formats/cover/__init__.py @@ -6,7 +6,7 @@ import re from PIL import Image, ImageFont, ImageDraw, ImageFilter from StringIO import StringIO -from librarian import DCNS +from librarian import DCNS, BuildError from librarian.output import OutputFile from librarian.utils import get_resource from librarian.formats import Format @@ -165,6 +165,9 @@ class Cover(Format): img = Image.new('RGB', (metr.width, metr.height), self.background_color) if self.background_img: + IMG_EXT = ('png', 'jpg', 'jpeg') + if '.' not in self.background_img or self.background_img.rsplit('.')[1].lower() not in IMG_EXT: + raise BuildError('Wrong cover format, should be PNG or JPG') background = Image.open(self.background_img) resized = background.resize((1024, background.height*1024/background.width), Image.ANTIALIAS) resized = resized.convert('RGBA') diff --git a/librarian/formats/cover/evens/__init__.py b/librarian/formats/cover/evens/__init__.py index e470001..a4b721c 100644 --- a/librarian/formats/cover/evens/__init__.py +++ b/librarian/formats/cover/evens/__init__.py @@ -20,6 +20,8 @@ class EvensCover(Cover): def set_images(self, ctx): cover_url = self.doc.meta.get(DCNS('relation.coverimage.url'))[0] + if not cover_url: + raise BuildError('No cover specified') if cover_url.startswith('file://'): cover_url = ctx.files_path + urllib.quote(cover_url[7:]) try: diff --git a/librarian/formats/epub/__init__.py b/librarian/formats/epub/__init__.py index 38443ee..4787a74 100644 --- a/librarian/formats/epub/__init__.py +++ b/librarian/formats/epub/__init__.py @@ -13,7 +13,7 @@ import zipfile from urllib2 import urlopen from lxml import etree -from librarian import OPFNS, NCXNS, XHTMLNS, DCNS +from librarian import OPFNS, NCXNS, XHTMLNS, DCNS, BuildError from librarian import core from librarian.formats import Format from librarian.formats.cover.evens import EvensCover @@ -340,6 +340,8 @@ class DivImageR(EpubRenderer): def render(self, element, ctx): src = element.attrib.get('src', '') ctx.images.append(src) + if '/' not in src: + raise BuildError('Bad image URL') src = src.rsplit('/', 1)[1] return super(DivImageR, self).render(element, Context(ctx, src=src)) diff --git a/librarian/formats/pdf/__init__.py b/librarian/formats/pdf/__init__.py index 0ff985f..fd1fd5e 100644 --- a/librarian/formats/pdf/__init__.py +++ b/librarian/formats/pdf/__init__.py @@ -11,7 +11,7 @@ from lxml import etree from urllib import urlretrieve from StringIO import StringIO from Texml.processor import process -from librarian import DCNS, XMLNamespace +from librarian import DCNS, XMLNamespace, BuildError from librarian.formats import Format from librarian.output import OutputFile from librarian.renderers import Register, TreeRenderer @@ -52,7 +52,8 @@ class PdfFormat(Format): def add_file(self, ctx, filename, url=None, path=None, image=False): from subprocess import call - assert url or path + if not url or path: + raise BuildError('No URL or path for image') save_as = os.path.join(ctx.workdir, filename) if path is not None: ext = path.rsplit('.', 1)[-1]