mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-04 03:27:00 -05:00 
			
		
		
		
	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:
		
							parent
							
								
									279594b1a3
								
							
						
					
					
						commit
						230cbf46b0
					
				@ -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:
 | 
				
			||||||
 | 
					            l = canonicalize_lang(getattr(opts, 'language', None))
 | 
				
			||||||
 | 
					            if not l:
 | 
				
			||||||
                oeb.logger.warn(u'Language not specified')
 | 
					                oeb.logger.warn(u'Language not specified')
 | 
				
			||||||
            metadata.add('language', get_lang().replace('_', '-'))
 | 
					                l = get_lang().replace('_', '-')
 | 
				
			||||||
 | 
					            metadata.add('language', l)
 | 
				
			||||||
        if not metadata.creator:
 | 
					        if not metadata.creator:
 | 
				
			||||||
 | 
					            a = getattr(opts, 'authors', None)
 | 
				
			||||||
 | 
					            if a:
 | 
				
			||||||
 | 
					                a = string_to_authors(a)
 | 
				
			||||||
 | 
					            if not a:
 | 
				
			||||||
                oeb.logger.warn('Creator not specified')
 | 
					                oeb.logger.warn('Creator not specified')
 | 
				
			||||||
            metadata.add('creator', self.oeb.translate(__('Unknown')))
 | 
					                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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user