1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-24 15:11:30 +02:00

Added first portion of logging adaptation.

Things may be broken at this point - there are still several modules to
be adapted.
This commit is contained in:
2021-06-22 22:04:43 +02:00
parent 6f898ab23e
commit 546cc26652
36 changed files with 326 additions and 316 deletions
@@ -112,7 +112,7 @@ class Reader132(FormatReader):
pml = ''
for i in range(1, self.header_record.num_text_pages + 1):
self.log.debug('Extracting text page %i' % i)
self.log.debug('Extracting text page %s', i)
pml += self.get_text_page(i)
hizer = PML_HTMLizer()
html += hizer.parse_pml(pml, 'index.html')
@@ -123,7 +123,7 @@ class Reader132(FormatReader):
footnoteids = re.findall(
'\\w+(?=\x00)', self.section_data(self.header_record.footnote_offset).decode('cp1252' if self.encoding is None else self.encoding))
for fid, i in enumerate(range(self.header_record.footnote_offset + 1, self.header_record.footnote_offset + self.header_record.footnote_count)):
self.log.debug('Extracting footnote page %i' % i)
self.log.debug('Extracting footnote page %s', i)
if fid < len(footnoteids):
fid = footnoteids[fid]
else:
@@ -135,7 +135,7 @@ class Reader132(FormatReader):
sidebarids = re.findall(
'\\w+(?=\x00)', self.section_data(self.header_record.sidebar_offset).decode('cp1252' if self.encoding is None else self.encoding))
for sid, i in enumerate(range(self.header_record.sidebar_offset + 1, self.header_record.sidebar_offset + self.header_record.sidebar_count)):
self.log.debug('Extracting sidebar page %i' % i)
self.log.debug('Extracting sidebar page %s', i)
if sid < len(sidebarids):
sid = sidebarids[sid]
else:
@@ -157,7 +157,7 @@ class Reader132(FormatReader):
name, img = self.get_image(self.header_record.image_data_offset + i)
images.append(name)
with open(name, 'wb') as imgf:
self.log.debug('Writing image %s to images/' % name)
self.log.debug('Writing image %s to images/', name)
imgf.write(img)
opf_path = self.create_opf(output_dir, images, toc)
@@ -87,7 +87,7 @@ class Reader202(FormatReader):
pml = ''
for i in range(1, self.header_record.num_text_pages + 1):
self.log.debug('Extracting text page %i' % i)
self.log.debug('Extracting text page %s', i)
pml += self.get_text_page(i)
title = self.mi.title
@@ -111,7 +111,7 @@ class Reader202(FormatReader):
if name:
images.append(name)
with open(name, 'wb') as imgf:
self.log.debug('Writing image %s to images/' % name)
self.log.debug('Writing image %s to images/', name)
imgf.write(img)
opf_path = self.create_opf(output_dir, images)
+3 -3
View File
@@ -116,9 +116,9 @@ class Reader(FormatReader):
def extract_content(self, output_dir):
txt = ''
self.log.info(u'Decompressing text...')
self.log.info('Decompressing text...')
for i in range(1, self.header_record.num_records + 1):
self.log.debug(u'\tDecompressing text section %i' % i)
self.log.debug('\tDecompressing text section %s', i)
title = self.header_record.chapter_titles[i-1]
lines = []
title_added = False
@@ -135,7 +135,7 @@ class Reader(FormatReader):
lines.insert(0, '<h1 class="chapter">' + title + '</h1>\n')
txt += '\n'.join(lines)
self.log.info(u'Converting text to OEB...')
self.log.info('Converting text to OEB...')
html = HTML_TEMPLATE % (self.header_record.title, txt)
with open(os.path.join(output_dir, 'index.html'), 'wb') as index:
index.write(html.encode('utf-8'))
+1 -1
View File
@@ -55,7 +55,7 @@ class Reader(FormatReader):
self.log.info('Decompressing text...')
for i in range(1, self.header_record.num_records + 1):
self.log.debug('\tDecompressing text section %i' % i)
self.log.debug('\tDecompressing text section %s', i)
raw_txt += self.decompress_text(i)
self.log.info('Converting text to OEB...')
+12 -6
View File
@@ -360,7 +360,8 @@ class Reader(FormatReader):
# plugin assemble the order based on hyperlinks.
with directory.CurrentDir(output_dir):
for uid, num in self.uid_text_secion_number.items():
self.log.debug('Writing record with uid: %s as %s.html' % (uid, uid))
self.log.debug('Writing record with uid: %s as %s.html',
uid, uid)
with open('%s.html' % uid, 'wb') as htmlf:
html = u'<html><body>'
section_header, section_data = self.sections[num]
@@ -393,11 +394,14 @@ class Reader(FormatReader):
try:
save_cover_data_to(idata, '%s.jpg' % uid, compression_quality=70)
images.add(uid)
self.log.debug('Wrote image with uid %s to images/%s.jpg' % (uid, uid))
self.log.debug('Wrote image with uid %s to '
'images/%s.jpg', uid, uid)
except Exception as e:
self.log.error('Failed to write image with uid %s: %s' % (uid, e))
self.log.error('Failed to write image with uid %s: %s',
uid, e)
else:
self.log.error('Failed to write image with uid %s: No data.' % uid)
self.log.error('Failed to write image with uid %s: '
'No data.', uid)
# Composite images.
# We're going to use the already compressed .jpg images here.
for uid, num in self.uid_composite_image_section_number.items():
@@ -436,9 +440,11 @@ class Reader(FormatReader):
y_off += largest_height
with open('%s.jpg' % uid) as out:
out.write(canvas.export(compression_quality=70))
self.log.debug('Wrote composite image with uid %s to images/%s.jpg' % (uid, uid))
self.log.debug('Wrote composite image with uid %s to '
'images/%s.jpg', uid, uid)
except Exception as e:
self.log.error('Failed to write composite image with uid %s: %s' % (uid, e))
self.log.error('Failed to write composite image with '
'uid %s: %s', uid, e)
# Run the HTML through the html processing plugin.
from ebook_converter.customize.ui import plugin_for_input_format
+2 -2
View File
@@ -54,7 +54,7 @@ class Reader(FormatReader):
if (self.header_record.flags & 0x01) == 0:
raise zTXTError('Only compression method 1 (random access) is supported')
self.log.debug('Foud ztxt version: %i.%i' % (vmajor, vminor))
self.log.debug('Foud ztxt version: %s.%s', vmajor, vminor)
# Initalize the decompressor
self.uncompressor = zlib.decompressobj()
@@ -73,7 +73,7 @@ class Reader(FormatReader):
self.log.info('Decompressing text...')
for i in range(1, self.header_record.num_records + 1):
self.log.debug('\tDecompressing text section %i' % i)
self.log.debug('\tDecompressing text section %s', i)
raw_txt += self.decompress_text(i)
self.log.info('Converting text to OEB...')