fnp
/
librarian.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
5135e07
)
error reporting
author
Jan Szejko
<janek37@gmail.com>
Tue, 27 Dec 2016 11:12:33 +0000
(12:12 +0100)
committer
Jan Szejko
<janek37@gmail.com>
Tue, 27 Dec 2016 11:12:33 +0000
(12:12 +0100)
librarian/formats/cover/__init__.py
patch
|
blob
|
history
librarian/formats/cover/evens/__init__.py
patch
|
blob
|
history
librarian/formats/epub/__init__.py
patch
|
blob
|
history
librarian/formats/pdf/__init__.py
patch
|
blob
|
history
diff --git
a/librarian/formats/cover/__init__.py
b/librarian/formats/cover/__init__.py
index
d410058
..
4788e39
100644
(file)
--- 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
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
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 = 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')
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
(file)
--- 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]
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:
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
(file)
--- 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 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
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)
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))
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
(file)
--- 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 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
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
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]
save_as = os.path.join(ctx.workdir, filename)
if path is not None:
ext = path.rsplit('.', 1)[-1]