mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-17 11:43:30 +02:00
Finalizing logging transition.
This commit is contained in:
@@ -215,8 +215,8 @@ class BookHeader(object):
|
||||
}[self.codepage]
|
||||
except (IndexError, KeyError):
|
||||
self.codec = 'cp1252' if not user_encoding else user_encoding
|
||||
log.warn('Unknown codepage %d. Assuming %s' % (self.codepage,
|
||||
self.codec))
|
||||
log.warning('Unknown codepage %d. Assuming %s', self.codepage,
|
||||
self.codec)
|
||||
# Some KF8 files have header length == 264 (generated by kindlegen
|
||||
# 2.9?). See https://bugs.launchpad.net/bugs/1179144
|
||||
max_header_length = 500 # We choose 500 for future versions of kindlegen
|
||||
|
||||
@@ -36,7 +36,8 @@ def update_internal_links(mobi8_reader, log):
|
||||
filename, idtag = mr.get_id_tag_by_pos_fid(
|
||||
int(posfid, 32), int(offset, 32))
|
||||
except ValueError:
|
||||
log.warn('Invalid link, points to nowhere, ignoring')
|
||||
log.warning('Invalid link, points to nowhere, '
|
||||
'ignoring')
|
||||
replacement = b'#'
|
||||
else:
|
||||
suffix = (b'#' + idtag) if idtag else b''
|
||||
@@ -49,7 +50,8 @@ def update_internal_links(mobi8_reader, log):
|
||||
try:
|
||||
parts.append(raw.decode(mr.header.codec))
|
||||
except UnicodeDecodeError:
|
||||
log.warn('Failed to decode text in KF8 part, replacing bad bytes')
|
||||
log.warning('Failed to decode text in KF8 part, replacing bad '
|
||||
'bytes')
|
||||
parts.append(raw.decode(mr.header.codec, 'replace'))
|
||||
|
||||
# All parts are now unicode and have no internal links
|
||||
@@ -130,7 +132,8 @@ def update_flow_links(mobi8_reader, resource_map, log):
|
||||
try:
|
||||
flow = flow.decode(mr.header.codec)
|
||||
except UnicodeDecodeError:
|
||||
log.error('Flow part has invalid %s encoded bytes'%mr.header.codec)
|
||||
log.error('Flow part has invalid %s encoded bytes',
|
||||
mr.header.codec)
|
||||
flow = flow.decode(mr.header.codec, 'replace')
|
||||
|
||||
# links to raster image files from image tags
|
||||
@@ -146,8 +149,8 @@ def update_flow_links(mobi8_reader, resource_map, log):
|
||||
replacement = '"%s"'%('../'+ href)
|
||||
tag = img_index_pattern.sub(replacement, tag, 1)
|
||||
else:
|
||||
log.warn('Referenced image %s was not recognized '
|
||||
'as a valid image in %s' % (num, tag))
|
||||
log.warning('Referenced image %s was not recognized '
|
||||
'as a valid image in %s', num, tag)
|
||||
srcpieces[j] = tag
|
||||
flow = "".join(srcpieces)
|
||||
|
||||
@@ -164,16 +167,16 @@ def update_flow_links(mobi8_reader, resource_map, log):
|
||||
replacement = '"%s"'%('../'+ href)
|
||||
tag = url_img_index_pattern.sub(replacement, tag, 1)
|
||||
else:
|
||||
log.warn('Referenced image %s was not recognized as a '
|
||||
'valid image in %s' % (num, tag))
|
||||
log.warning('Referenced image %s was not recognized as a '
|
||||
'valid image in %s', num, tag)
|
||||
|
||||
# process links to fonts
|
||||
for m in font_index_pattern.finditer(tag):
|
||||
num = int(m.group(1), 32)
|
||||
href = resource_map[num-1]
|
||||
if href is None:
|
||||
log.warn('Referenced font %s was not recognized as a '
|
||||
'valid font in %s' % (num, tag))
|
||||
log.warning('Referenced font %s was not recognized as a '
|
||||
'valid font in %s', num, tag)
|
||||
else:
|
||||
replacement = '"%s"'%('../'+ href)
|
||||
if href.endswith('.failed'):
|
||||
@@ -200,7 +203,8 @@ def update_flow_links(mobi8_reader, resource_map, log):
|
||||
num = int(m.group(1), 32)
|
||||
fi = mr.flowinfo[num]
|
||||
except IndexError:
|
||||
log.warn('Ignoring invalid flow reference in tag', tag)
|
||||
log.warning('Ignoring invalid flow reference in '
|
||||
'tag %s', tag)
|
||||
tag = ''
|
||||
else:
|
||||
if fi.format == 'inline':
|
||||
@@ -237,7 +241,8 @@ def insert_flows_into_markup(parts, flows, mobi8_reader, log):
|
||||
try:
|
||||
fi = mr.flowinfo[num]
|
||||
except IndexError:
|
||||
log.warn('Ignoring invalid flow reference: %s'%m.group())
|
||||
log.warning('Ignoring invalid flow reference: %s',
|
||||
m.group())
|
||||
tag = ''
|
||||
else:
|
||||
if fi.format == 'inline':
|
||||
@@ -273,8 +278,8 @@ def insert_images_into_markup(parts, resource_map, log):
|
||||
replacement = '"%s"'%('../' + href)
|
||||
tag = img_index_pattern.sub(replacement, tag, 1)
|
||||
else:
|
||||
log.warn('Referenced image %s was not recognized as '
|
||||
'a valid image in %s' % (num, tag))
|
||||
log.warning('Referenced image %s was not recognized '
|
||||
'as a valid image in %s', num, tag)
|
||||
srcpieces[j] = tag
|
||||
part = "".join(srcpieces)
|
||||
# store away modified version
|
||||
@@ -296,8 +301,8 @@ def insert_images_into_markup(parts, resource_map, log):
|
||||
replacement = '%s%s%s'%(osep, '../' + href, csep)
|
||||
tag = img_index_pattern.sub(replacement, tag, 1)
|
||||
else:
|
||||
log.warn('Referenced image %s was not recognized as '
|
||||
'a valid image in %s' % (num, tag))
|
||||
log.warning('Referenced image %s was not recognized '
|
||||
'as a valid image in %s', num, tag)
|
||||
srcpieces[j] = tag
|
||||
part = "".join(srcpieces)
|
||||
# store away modified version
|
||||
|
||||
@@ -231,7 +231,7 @@ class MobiReader(object):
|
||||
keep_doctype=False, sanitize_names=True)
|
||||
|
||||
if root.tag != 'html':
|
||||
self.log.warn('File does not have opening <html> tag')
|
||||
self.log.warning('File does not have opening <html> tag')
|
||||
nroot = html.fromstring('<html><head></head><body></body></html>')
|
||||
bod = nroot.find('body')
|
||||
for child in list(root):
|
||||
@@ -242,7 +242,7 @@ class MobiReader(object):
|
||||
htmls = list(root.xpath('//html'))
|
||||
|
||||
if len(htmls) > 1:
|
||||
self.log.warn('Markup contains multiple <html> tags, merging.')
|
||||
self.log.warning('Markup contains multiple <html> tags, merging.')
|
||||
# Merge all <head> and <body> sections
|
||||
for h in htmls:
|
||||
p = h.getparent()
|
||||
@@ -833,9 +833,9 @@ class MobiReader(object):
|
||||
def warn_about_trailing_entry_corruption(self):
|
||||
if not self.warned_about_trailing_entry_corruption:
|
||||
self.warned_about_trailing_entry_corruption = True
|
||||
self.log.warn('The trailing data entries in this MOBI file are '
|
||||
'corrupted, you might see corrupted text in the '
|
||||
'output')
|
||||
self.log.warning('The trailing data entries in this MOBI file are '
|
||||
'corrupted, you might see corrupted text in the '
|
||||
'output')
|
||||
|
||||
def text_section(self, index):
|
||||
data = self.sections[index][0]
|
||||
|
||||
@@ -205,9 +205,9 @@ class Mobi8Reader(object):
|
||||
# This can happen for some badly formed KF8 files, see for
|
||||
# example, https://bugs.launchpad.net/bugs/1082669
|
||||
if not inspos_warned:
|
||||
self.log.warn('The div table for %s has incorrect '
|
||||
'insert positions. Calculating '
|
||||
'manually.' % skelname)
|
||||
self.log.warning('The div table for %s has incorrect '
|
||||
'insert positions. Calculating '
|
||||
'manually.', skelname)
|
||||
inspos_warned = True
|
||||
bp, ep = locate_beg_end_of_tag(skeleton, aidtext if
|
||||
isinstance(aidtext, bytes)
|
||||
@@ -396,8 +396,8 @@ class Mobi8Reader(object):
|
||||
try:
|
||||
href, idtag = self.get_id_tag_by_pos_fid(*pos_fid)
|
||||
except ValueError:
|
||||
self.log.warn('Invalid entry in NCX (title: %s), '
|
||||
'ignoring' % entry['text'])
|
||||
self.log.warning('Invalid entry in NCX (title: %s), '
|
||||
'ignoring', entry['text'])
|
||||
remove.append(entry)
|
||||
continue
|
||||
|
||||
@@ -436,10 +436,10 @@ class Mobi8Reader(object):
|
||||
font = read_font_record(data)
|
||||
href = "fonts/%05d.%s" % (fname_idx, font['ext'])
|
||||
if font['err']:
|
||||
self.log.warn('Reading font record %d failed: %s' %
|
||||
(fname_idx, font['err']))
|
||||
self.log.warning('Reading font record %d failed: %s',
|
||||
fname_idx, font['err'])
|
||||
if font['headers']:
|
||||
self.log.debug('Font record headers: %s' %
|
||||
self.log.debug('Font record headers: %s',
|
||||
font['headers'])
|
||||
with open(href.replace('/', os.sep), 'wb') as f:
|
||||
f.write(font['font_data'] if font['font_data'] else
|
||||
@@ -484,7 +484,7 @@ class Mobi8Reader(object):
|
||||
mi.cover = resource_map[self.cover_offset]
|
||||
|
||||
if len(list(toc)) < 2:
|
||||
self.log.warn('KF8 has no metadata Table of Contents')
|
||||
self.log.warning('KF8 has no metadata Table of Contents')
|
||||
|
||||
for ref in guide:
|
||||
if ref.type == 'toc':
|
||||
|
||||
Reference in New Issue
Block a user