mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #5083 (multi-file html to ePub conversion fails on Mac OS X w/ case-sensitive filesystems)
This commit is contained in:
parent
ee411e3187
commit
8dc171ee3a
@ -11,7 +11,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
Input plugin for HTML or OPF ebooks.
|
Input plugin for HTML or OPF ebooks.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os, re, sys, uuid
|
import os, re, sys, uuid, tempfile
|
||||||
from urlparse import urlparse, urlunparse
|
from urlparse import urlparse, urlunparse
|
||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
from functools import partial
|
from functools import partial
|
||||||
@ -272,6 +272,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
|
|
||||||
def convert(self, stream, opts, file_ext, log,
|
def convert(self, stream, opts, file_ext, log,
|
||||||
accelerators):
|
accelerators):
|
||||||
|
self._is_case_sensitive = None
|
||||||
basedir = os.getcwd()
|
basedir = os.getcwd()
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
|
|
||||||
@ -290,6 +291,15 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
return create_oebbook(log, stream.name, opts, self,
|
return create_oebbook(log, stream.name, opts, self,
|
||||||
encoding=opts.input_encoding)
|
encoding=opts.input_encoding)
|
||||||
|
|
||||||
|
def is_case_sensitive(self, path):
|
||||||
|
if self._is_case_sensitive is not None:
|
||||||
|
return self._is_case_sensitive
|
||||||
|
if not path or not os.path.exists(path):
|
||||||
|
return islinux or isfreebsd
|
||||||
|
self._is_case_sensitive = os.path.exists(path.lower()) \
|
||||||
|
and os.path.exists(path.upper())
|
||||||
|
return self._is_case_sensitive
|
||||||
|
|
||||||
def create_oebbook(self, htmlpath, basedir, opts, log, mi):
|
def create_oebbook(self, htmlpath, basedir, opts, log, mi):
|
||||||
from calibre.ebooks.conversion.plumber import create_oebbook
|
from calibre.ebooks.conversion.plumber import create_oebbook
|
||||||
from calibre.ebooks.oeb.base import DirContainer, \
|
from calibre.ebooks.oeb.base import DirContainer, \
|
||||||
@ -343,14 +353,16 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
|
|
||||||
self.added_resources = {}
|
self.added_resources = {}
|
||||||
self.log = log
|
self.log = log
|
||||||
|
self.log('Normalizing filename cases')
|
||||||
for path, href in htmlfile_map.items():
|
for path, href in htmlfile_map.items():
|
||||||
if not (islinux or isfreebsd):
|
if not self.is_case_sensitive(path):
|
||||||
path = path.lower()
|
path = path.lower()
|
||||||
self.added_resources[path] = href
|
self.added_resources[path] = href
|
||||||
self.urlnormalize, self.DirContainer = urlnormalize, DirContainer
|
self.urlnormalize, self.DirContainer = urlnormalize, DirContainer
|
||||||
self.urldefrag = urldefrag
|
self.urldefrag = urldefrag
|
||||||
self.guess_type, self.BINARY_MIME = guess_type, BINARY_MIME
|
self.guess_type, self.BINARY_MIME = guess_type, BINARY_MIME
|
||||||
|
|
||||||
|
self.log('Rewriting HTML links')
|
||||||
for f in filelist:
|
for f in filelist:
|
||||||
path = f.path
|
path = f.path
|
||||||
dpath = os.path.dirname(path)
|
dpath = os.path.dirname(path)
|
||||||
@ -415,7 +427,7 @@ class HTMLInput(InputFormatPlugin):
|
|||||||
if os.path.isdir(link):
|
if os.path.isdir(link):
|
||||||
self.log.warn(link_, 'is a link to a directory. Ignoring.')
|
self.log.warn(link_, 'is a link to a directory. Ignoring.')
|
||||||
return link_
|
return link_
|
||||||
if not (islinux or isfreebsd):
|
if not self.is_case_sensitive(tempfile.gettempdir()):
|
||||||
link = link.lower()
|
link = link.lower()
|
||||||
if link not in self.added_resources:
|
if link not in self.added_resources:
|
||||||
bhref = os.path.basename(link)
|
bhref = os.path.basename(link)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user