Edit Book: Check Book: Add a warning for links with the : character in them on windows

This commit is contained in:
Kovid Goyal 2016-11-12 08:09:59 +05:30
parent 3f5f29377f
commit 415fb9c317

View File

@ -14,7 +14,7 @@ from threading import Thread
from Queue import Queue, Empty from Queue import Queue, Empty
from calibre import browser from calibre import browser
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, urlunquote
from calibre.ebooks.oeb.polish.container import OEB_FONTS from calibre.ebooks.oeb.polish.container import OEB_FONTS
from calibre.ebooks.oeb.polish.replace import remove_links_to from calibre.ebooks.oeb.polish.replace import remove_links_to
from calibre.ebooks.oeb.polish.cover import get_raster_cover_name from calibre.ebooks.oeb.polish.cover import get_raster_cover_name
@ -29,6 +29,12 @@ class BadLink(BaseError):
level = WARN level = WARN
class InvalidCharInLink(BadLink):
HELP = _('Windows computers do not allow the : character in filenames. For maximum'
' compatibility it is best to not use these in filenames/links to files.')
class CaseMismatch(BadLink): class CaseMismatch(BadLink):
def __init__(self, href, corrected_name, name, lnum, col): def __init__(self, href, corrected_name, name, lnum, col):
@ -342,6 +348,8 @@ def check_links(container):
a(FileLink(_('The link %s is a file:// URL') % fl(href), name, lnum, col)) a(FileLink(_('The link %s is a file:// URL') % fl(href), name, lnum, col))
elif purl.path and purl.path.startswith('/') and purl.scheme in {'', 'file'}: elif purl.path and purl.path.startswith('/') and purl.scheme in {'', 'file'}:
a(LocalLink(_('The link %s points to a file outside the book') % fl(href), name, lnum, col)) a(LocalLink(_('The link %s points to a file outside the book') % fl(href), name, lnum, col))
elif purl.path and purl.scheme in {'', 'file'} and ':' in urlunquote(purl.path):
a(InvalidCharInLink(_('The link %s contains a : character, this will cause errors on windows computers') % fl(href), name, lnum, col))
spine_docs = {name for name, linear in container.spine_names} spine_docs = {name for name, linear in container.spine_names}
spine_styles = {tname for name in spine_docs for tname in links_map[name] if container.mime_map.get(tname, None) in OEB_STYLES} spine_styles = {tname for name in spine_docs for tname in links_map[name] if container.mime_map.get(tname, None) in OEB_STYLES}