Cleanup previous PR

This commit is contained in:
Kovid Goyal 2024-08-04 14:42:46 +05:30
parent 74d685ffa4
commit 0ce8e9af3c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -10,7 +10,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import io import io
import os import os
import posixpath import posixpath
from contextlib import closing from contextlib import closing, suppress
from calibre import CurrentDir from calibre import CurrentDir
from calibre.ebooks.metadata.opf import get_metadata as get_metadata_from_opf from calibre.ebooks.metadata.opf import get_metadata as get_metadata_from_opf
@ -22,6 +22,7 @@ from calibre.utils.localunzip import LocalZipFile
from calibre.utils.xml_parse import safe_xml_fromstring from calibre.utils.xml_parse import safe_xml_fromstring
from calibre.utils.zipfile import BadZipfile, ZipFile, safe_replace from calibre.utils.zipfile import BadZipfile, ZipFile, safe_replace
class EPubException(Exception): class EPubException(Exception):
pass pass
@ -133,7 +134,7 @@ class OCFReader(OCF):
def exists(self, path): def exists(self, path):
try: try:
self.open(path) self.open(path).close()
return True return True
except OSError: except OSError:
return False return False
@ -214,16 +215,17 @@ def render_cover(cpage, zf, reader=None):
if not os.path.exists(cpage): if not os.path.exists(cpage):
return return
# In the case of manga, the first spine item may be an image with suppress(Exception):
# already, so treat it as a raster cover. # In the case of manga, the first spine item may be an image
file_format = what_image_type(cpage) # already, so treat it as a raster cover.
if file_format == "jpeg": file_format = what_image_type(cpage)
# Only JPEG is allowed since elsewhere we assume raster covers if file_format == "jpeg":
# are JPEG. In principle we could convert other image formats # Only JPEG is allowed since elsewhere we assume raster covers
# but this is already an out-of-spec case that happens to # are JPEG. In principle we could convert other image formats
# arise in books from some stores. # but this is already an out-of-spec case that happens to
with open(cpage, "rb") as source: # arise in books from some stores.
return source.read() with open(cpage, "rb") as source:
return source.read()
return render_html_svg_workaround(cpage, default_log, root=tdir) return render_html_svg_workaround(cpage, default_log, root=tdir)