HTML Input: Avoid spurious log warnings

HTML Input: Avoid spurious log warnings about unspecified
language/creator when these are actually specified on the command line.
Fixes #1186899 [Apparently-spurious "Language not specified" errors from caliber-convert](https://bugs.launchpad.net/calibre/+bug/1186899)
This commit is contained in:
Kovid Goyal 2013-06-03 14:04:33 +05:30
parent 279594b1a3
commit 230cbf46b0

View File

@ -87,7 +87,7 @@ class HTMLInput(InputFormatPlugin):
return self._is_case_sensitive return self._is_case_sensitive
if not path or not os.path.exists(path): if not path or not os.path.exists(path):
return islinux or isbsd return islinux or isbsd
self._is_case_sensitive = not (os.path.exists(path.lower()) \ self._is_case_sensitive = not (os.path.exists(path.lower())
and os.path.exists(path.upper())) and os.path.exists(path.upper()))
return self._is_case_sensitive return self._is_case_sensitive
@ -101,6 +101,8 @@ class HTMLInput(InputFormatPlugin):
from calibre.ebooks.oeb.transforms.metadata import \ from calibre.ebooks.oeb.transforms.metadata import \
meta_info_to_oeb_metadata meta_info_to_oeb_metadata
from calibre.ebooks.html.input import get_filelist from calibre.ebooks.html.input import get_filelist
from calibre.ebooks.metadata import string_to_authors
from calibre.utils.localization import canonicalize_lang
import cssutils, logging import cssutils, logging
cssutils.log.setLevel(logging.WARN) cssutils.log.setLevel(logging.WARN)
self.OEB_STYLES = OEB_STYLES self.OEB_STYLES = OEB_STYLES
@ -111,11 +113,20 @@ class HTMLInput(InputFormatPlugin):
metadata = oeb.metadata metadata = oeb.metadata
meta_info_to_oeb_metadata(mi, metadata, log) meta_info_to_oeb_metadata(mi, metadata, log)
if not metadata.language: if not metadata.language:
oeb.logger.warn(u'Language not specified') l = canonicalize_lang(getattr(opts, 'language', None))
metadata.add('language', get_lang().replace('_', '-')) if not l:
oeb.logger.warn(u'Language not specified')
l = get_lang().replace('_', '-')
metadata.add('language', l)
if not metadata.creator: if not metadata.creator:
oeb.logger.warn('Creator not specified') a = getattr(opts, 'authors', None)
metadata.add('creator', self.oeb.translate(__('Unknown'))) if a:
a = string_to_authors(a)
if not a:
oeb.logger.warn('Creator not specified')
a = [self.oeb.translate(__('Unknown'))]
for aut in a:
metadata.add('creator', aut)
if not metadata.title: if not metadata.title:
oeb.logger.warn('Title not specified') oeb.logger.warn('Title not specified')
metadata.add('title', self.oeb.translate(__('Unknown'))) metadata.add('title', self.oeb.translate(__('Unknown')))
@ -175,7 +186,8 @@ class HTMLInput(InputFormatPlugin):
titles = [] titles = []
headers = [] headers = []
for item in self.oeb.spine: for item in self.oeb.spine:
if not item.linear: continue if not item.linear:
continue
html = item.data html = item.data
title = ''.join(xpath(html, '/h:html/h:head/h:title/text()')) title = ''.join(xpath(html, '/h:html/h:head/h:title/text()'))
title = re.sub(r'\s+', ' ', title.strip()) title = re.sub(r'\s+', ' ', title.strip())
@ -193,7 +205,8 @@ class HTMLInput(InputFormatPlugin):
if len(titles) > len(set(titles)): if len(titles) > len(set(titles)):
use = headers use = headers
for title, item in izip(use, self.oeb.spine): for title, item in izip(use, self.oeb.spine):
if not item.linear: continue if not item.linear:
continue
toc.add(title, item.href) toc.add(title, item.href)
oeb.container = DirContainer(os.getcwdu(), oeb.log, ignore_opf=True) oeb.container = DirContainer(os.getcwdu(), oeb.log, ignore_opf=True)
@ -291,3 +304,4 @@ class HTMLInput(InputFormatPlugin):
self.log.exception('Failed to read CSS file: %r'%link) self.log.exception('Failed to read CSS file: %r'%link)
return (None, None) return (None, None)
return (None, raw) return (None, raw)