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
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')
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:
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
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))
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
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]