1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-27 17:13:32 +02:00

Cleaned up __init__.py for main module

This commit is contained in:
2021-01-05 19:48:45 +01:00
parent 8a757f60a6
commit b2f161670a
15 changed files with 55 additions and 85 deletions
@@ -6,16 +6,11 @@ import re
import struct
import zlib
from ebook_converter import CurrentDir
from ebook_converter.ebooks import DRMError
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
from ebook_converter.ebooks.pdb.ereader import EreaderError
from ebook_converter.ebooks.pdb.formatreader import FormatReader
__license__ = 'GPL v3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from ebook_converter.utils import directory
class HeaderRecord(object):
@@ -149,7 +144,7 @@ class Reader132(FormatReader):
html += '</body></html>'
with CurrentDir(output_dir):
with directory.CurrentDir(output_dir):
with open('index.html', 'wb') as index:
self.log.debug('Writing text to index.html')
index.write(html.encode('utf-8'))
@@ -157,7 +152,7 @@ class Reader132(FormatReader):
if not os.path.exists(os.path.join(output_dir, 'images/')):
os.makedirs(os.path.join(output_dir, 'images/'))
images = []
with CurrentDir(os.path.join(output_dir, 'images/')):
with directory.CurrentDir(os.path.join(output_dir, 'images/')):
for i in range(0, self.header_record.num_image_pages):
name, img = self.get_image(self.header_record.image_data_offset + i)
images.append(name)
@@ -170,7 +165,7 @@ class Reader132(FormatReader):
return opf_path
def create_opf(self, output_dir, images, toc):
with CurrentDir(output_dir):
with directory.CurrentDir(output_dir):
if 'cover.png' in images:
self.mi.cover = os.path.join('images', 'cover.png')
@@ -210,7 +205,7 @@ class Reader132(FormatReader):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
with CurrentDir(output_dir):
with directory.CurrentDir(output_dir):
for i in range(0, self.header_record.num_image_pages):
name, img = self.get_image(self.header_record.image_data_offset + i)
with open(name, 'wb') as imgf:
@@ -5,17 +5,12 @@ Makebook.
import os
import struct
from ebook_converter import CurrentDir
from ebook_converter.utils import directory
from ebook_converter.ebooks.metadata.opf2 import OPFCreator
from ebook_converter.ebooks.pdb.formatreader import FormatReader
from ebook_converter.ebooks.pdb.ereader import EreaderError
__license__ = 'GPL v3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
class HeaderRecord(object):
'''
The first record in the file is always the header record. It holds
@@ -102,7 +97,7 @@ class Reader202(FormatReader):
html = '<html><head><title>%s</title></head><body>%s</body></html>' % \
(title, pml_to_html(pml))
with CurrentDir(output_dir):
with directory.CurrentDir(output_dir):
with open('index.html', 'wb') as index:
self.log.debug('Writing text to index.html')
index.write(html.encode('utf-8'))
@@ -110,7 +105,7 @@ class Reader202(FormatReader):
if not os.path.exists(os.path.join(output_dir, 'images/')):
os.makedirs(os.path.join(output_dir, 'images/'))
images = []
with CurrentDir(os.path.join(output_dir, 'images/')):
with directory.CurrentDir(os.path.join(output_dir, 'images/')):
for i in range(self.header_record.non_text_offset, len(self.sections)):
name, img = self.get_image(i)
if name:
@@ -124,7 +119,7 @@ class Reader202(FormatReader):
return opf_path
def create_opf(self, output_dir, images):
with CurrentDir(output_dir):
with directory.CurrentDir(output_dir):
opf = OPFCreator(output_dir, self.mi)
manifest = [('index.html', None)]
@@ -159,7 +154,7 @@ class Reader202(FormatReader):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
with CurrentDir(output_dir):
with directory.CurrentDir(output_dir):
for i in range(0, self.header_record.num_image_pages):
name, img = self.get_image(self.header_record.image_data_offset + i)
with open(name, 'wb') as imgf:
+3 -3
View File
@@ -4,7 +4,7 @@ import zlib
from collections import OrderedDict
from ebook_converter import CurrentDir
from ebook_converter.utils import directory
from ebook_converter.ebooks.pdb.formatreader import FormatReader
from ebook_converter.ebooks.compression.palmdoc import decompress_doc
from ebook_converter.utils.imghdr import identify
@@ -358,7 +358,7 @@ class Reader(FormatReader):
# text recored into a separate file. We will reference the
# home.html file as the first file and let the HTML input
# plugin assemble the order based on hyperlinks.
with CurrentDir(output_dir):
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))
with open('%s.html' % uid, 'wb') as htmlf:
@@ -377,7 +377,7 @@ class Reader(FormatReader):
images = set()
if not os.path.exists(os.path.join(output_dir, 'images/')):
os.makedirs(os.path.join(output_dir, 'images/'))
with CurrentDir(os.path.join(output_dir, 'images/')):
with directory.CurrentDir(os.path.join(output_dir, 'images/')):
# Single images.
for uid, num in self.uid_image_section_number.items():
section_header, section_data = self.sections[num]