1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-13 04:55:49 +01:00

Changing logging module location.

This commit is contained in:
2021-06-28 22:02:41 +02:00
parent b574357c2c
commit 3f57198f91
10 changed files with 41 additions and 30 deletions

View File

@@ -185,7 +185,7 @@ class InputFormatPlugin(Plugin):
:param file_ext: The extension (without the .) of the input file. It :param file_ext: The extension (without the .) of the input file. It
is guaranteed to be one of the `file_types` supported is guaranteed to be one of the `file_types` supported
by this plugin. by this plugin.
:param log: A :class:`calibre.utils.logging.Log` object. All output :param log: A :class:`calibre.logging.Logger` object. All output
should use this object. should use this object.
:param accelarators: A dictionary of various information that the input :param accelarators: A dictionary of various information that the input
plugin can get easily that would speed up the plugin can get easily that would speed up the

View File

@@ -260,8 +260,9 @@ if __name__ == '__main__':
opts.output_profile = HanlinV3Output(None) opts.output_profile = HanlinV3Output(None)
html_preprocessor = HTMLPreProcessor(None, None, opts) html_preprocessor = HTMLPreProcessor(None, None, opts)
from ebook_converter.utils.logging import default_log from ebook_converter import logging
oeb = OEBBook(default_log, html_preprocessor) oeb = OEBBook(logging.default_log, html_preprocessor)
reader = OEBReader reader = OEBReader
reader()(oeb, '/tmp/bbb/processed/') reader()(oeb, '/tmp/bbb/processed/')
SNBOutput(None).convert(oeb, '/tmp/test.snb', None, None, default_log) SNBOutput(None).convert(oeb, '/tmp/test.snb', None, None,
logging.default_log)

View File

@@ -1,14 +1,17 @@
import re import re
from math import ceil from math import ceil
from ebook_converter.ebooks.conversion.preprocess import DocAnalysis, Dehyphenator from ebook_converter.ebooks.conversion.preprocess import DocAnalysis, Dehyphenator
from ebook_converter.utils.logging import default_log from ebook_converter import logging
from ebook_converter.utils.wordcount import get_wordcount_obj from ebook_converter.utils.wordcount import get_wordcount_obj
LOG = logging.default_log
class HeuristicProcessor(object): class HeuristicProcessor(object):
def __init__(self, extra_opts=None, log=None): def __init__(self, extra_opts=None, log=None):
self.log = default_log if log is None else log self.log = LOG if log is None else log
self.html_preprocess_sections = 0 self.html_preprocess_sections = 0
self.found_indents = 0 self.found_indents = 0
self.extra_opts = extra_opts self.extra_opts = extra_opts

View File

@@ -12,10 +12,13 @@ from ebook_converter.ebooks.docx import InvalidDOCX
from ebook_converter.ebooks.docx.names import DOCXNamespace from ebook_converter.ebooks.docx.names import DOCXNamespace
from ebook_converter.ptempfile import PersistentTemporaryDirectory from ebook_converter.ptempfile import PersistentTemporaryDirectory
from ebook_converter.utils.localization import canonicalize_lang from ebook_converter.utils.localization import canonicalize_lang
from ebook_converter.utils.logging import default_log from ebook_converter import logging
from ebook_converter.utils.zipfile import ZipFile from ebook_converter.utils.zipfile import ZipFile
LOG = logging.default_log
# Read metadata {{{ # Read metadata {{{
def read_doc_props(raw, mi, XPath): def read_doc_props(raw, mi, XPath):
root = etree.fromstring(raw) root = etree.fromstring(raw)
@@ -86,7 +89,7 @@ class DOCX(object):
if not hasattr(path_or_stream, 'read'): if not hasattr(path_or_stream, 'read'):
stream = open(path_or_stream, 'rb') stream = open(path_or_stream, 'rb')
self.name = getattr(stream, 'name', None) or '<stream>' self.name = getattr(stream, 'name', None) or '<stream>'
self.log = log or default_log self.log = log or LOG
if extract: if extract:
self.extract(stream) self.extract(stream)
else: else:

View File

@@ -881,10 +881,11 @@ class Convert(object):
if __name__ == '__main__': if __name__ == '__main__':
import shutil import shutil
from ebook_converter.utils.logging import default_log from ebook_converter import logging
default_log.filter_level = default_log.DEBUG logging.default_log.filter_level = logging.default_log.DEBUG
dest_dir = os.path.join(os.getcwd(), 'docx_input') dest_dir = os.path.join(os.getcwd(), 'docx_input')
if os.path.exists(dest_dir): if os.path.exists(dest_dir):
shutil.rmtree(dest_dir) shutil.rmtree(dest_dir)
os.mkdir(dest_dir) os.mkdir(dest_dir)
Convert(sys.argv[-1], dest_dir=dest_dir, log=default_log)() Convert(sys.argv[-1], dest_dir=dest_dir,
log=logging.default_log)()

View File

@@ -13,12 +13,13 @@ from ebook_converter.ebooks.oeb import base
from ebook_converter.ebooks.oeb import parse_utils from ebook_converter.ebooks.oeb import parse_utils
from ebook_converter.ebooks.oeb.stylizer import Stylizer from ebook_converter.ebooks.oeb.stylizer import Stylizer
from ebook_converter.utils import entities from ebook_converter.utils import entities
from ebook_converter.utils.logging import default_log from ebook_converter import logging
from ebook_converter import polyglot from ebook_converter import polyglot
SELF_CLOSING_TAGS = {'area', 'base', 'basefont', 'br', 'hr', 'input', 'img', SELF_CLOSING_TAGS = {'area', 'base', 'basefont', 'br', 'hr', 'input', 'img',
'link', 'meta'} 'link', 'meta'}
LOG = logging.default_log
class OEB2HTML(object): class OEB2HTML(object):
@@ -34,7 +35,7 @@ class OEB2HTML(object):
""" """
def __init__(self, log=None): def __init__(self, log=None):
self.log = default_log if log is None else log self.log = LOG if log is None else log
self.links = {} self.links = {}
self.images = {} self.images = {}

View File

@@ -4,7 +4,7 @@ import os
from ebook_converter.ebooks.mobi import MobiError from ebook_converter.ebooks.mobi import MobiError
from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader
from ebook_converter.ebooks.mobi.reader.headers import MetadataHeader from ebook_converter.ebooks.mobi.reader.headers import MetadataHeader
from ebook_converter.utils.logging import default_log from ebook_converter import logging
from ebook_converter.ebooks import DRMError from ebook_converter.ebooks import DRMError
from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader
from ebook_converter.ebooks.conversion.plumber import Plumber, create_oebbook from ebook_converter.ebooks.conversion.plumber import Plumber, create_oebbook
@@ -14,9 +14,7 @@ from ebook_converter.utils import directory
from ebook_converter.utils.ipc.simple_worker import fork_job from ebook_converter.utils.ipc.simple_worker import fork_job
__license__ = 'GPL v3' LOG = logging.default_log
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
class BadFormat(ValueError): class BadFormat(ValueError):
@@ -25,10 +23,10 @@ class BadFormat(ValueError):
def do_explode(path, dest): def do_explode(path, dest):
with open(path, 'rb') as stream: with open(path, 'rb') as stream:
mr = MobiReader(stream, default_log, None, None) mr = MobiReader(stream, LOG, None, None)
with directory.CurrentDir(dest): with directory.CurrentDir(dest):
mr = Mobi8Reader(mr, default_log) mr = Mobi8Reader(mr, LOG)
opf = os.path.abspath(mr()) opf = os.path.abspath(mr())
try: try:
os.remove('debug-raw.html') os.remove('debug-raw.html')
@@ -46,7 +44,7 @@ def explode(path, dest, question=lambda x: True):
raise BadFormat('This is not a MOBI file. It is a Topaz file.') raise BadFormat('This is not a MOBI file. It is a Topaz file.')
try: try:
header = MetadataHeader(stream, default_log) header = MetadataHeader(stream, LOG)
except MobiError: except MobiError:
raise BadFormat('This is not a MOBI file.') raise BadFormat('This is not a MOBI file.')
@@ -85,15 +83,15 @@ def set_cover(oeb):
def do_rebuild(opf, dest_path): def do_rebuild(opf, dest_path):
plumber = Plumber(opf, dest_path, default_log) plumber = Plumber(opf, dest_path, LOG)
plumber.setup_options() plumber.setup_options()
inp = plugin_for_input_format('azw3') inp = plugin_for_input_format('azw3')
outp = plugin_for_output_format('azw3') outp = plugin_for_output_format('azw3')
plumber.opts.mobi_passthrough = True plumber.opts.mobi_passthrough = True
oeb = create_oebbook(default_log, opf, plumber.opts) oeb = create_oebbook(LOG, opf, plumber.opts)
set_cover(oeb) set_cover(oeb)
outp.convert(oeb, dest_path, inp, plumber.opts, default_log) outp.convert(oeb, dest_path, inp, plumber.opts, LOG)
def rebuild(src_dir, dest_path): def rebuild(src_dir, dest_path):

View File

@@ -43,13 +43,14 @@ from ebook_converter.ptempfile import PersistentTemporaryDirectory, PersistentTe
from ebook_converter.utils import directory from ebook_converter.utils import directory
from ebook_converter.utils.filenames import hardlink_file, nlinks_file from ebook_converter.utils.filenames import hardlink_file, nlinks_file
from ebook_converter.utils.ipc.simple_worker import WorkerError, fork_job from ebook_converter.utils.ipc.simple_worker import WorkerError, fork_job
from ebook_converter.utils.logging import default_log from ebook_converter import logging
from ebook_converter.utils.zipfile import ZipFile from ebook_converter.utils.zipfile import ZipFile
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
OEB_FONTS = {guess_type('a.ttf'), guess_type('b.otf'), guess_type('a.woff'), 'application/x-font-ttf', 'application/x-font-otf', 'application/font-sfnt'} OEB_FONTS = {guess_type('a.ttf'), guess_type('b.otf'), guess_type('a.woff'), 'application/x-font-ttf', 'application/x-font-otf', 'application/font-sfnt'}
null = object() null = object()
LOG = logging.default_log
class CSSPreProcessor(cssp): class CSSPreProcessor(cssp):
@@ -1391,10 +1392,10 @@ def do_explode(path, dest):
from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader
from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader
with open(path, 'rb') as stream: with open(path, 'rb') as stream:
mr = MobiReader(stream, default_log, None, None) mr = MobiReader(stream, LOG, None, None)
with directory.CurrentDir(dest): with directory.CurrentDir(dest):
mr = Mobi8Reader(mr, default_log, for_tweak=True) mr = Mobi8Reader(mr, LOG, for_tweak=True)
opf = os.path.abspath(mr()) opf = os.path.abspath(mr())
obfuscated_fonts = mr.encrypted_fonts obfuscated_fonts = mr.encrypted_fonts
@@ -1455,7 +1456,7 @@ class AZW3Container(Container):
'file.') 'file.')
try: try:
header = MetadataHeader(stream, default_log) header = MetadataHeader(stream, LOG)
except MobiError: except MobiError:
raise InvalidMobi('This is not a MOBI file.') raise InvalidMobi('This is not a MOBI file.')
@@ -1514,7 +1515,7 @@ class AZW3Container(Container):
def get_container(path, log=None, tdir=None, tweak_mode=False): def get_container(path, log=None, tdir=None, tweak_mode=False):
if log is None: if log is None:
log = default_log log = LOG
try: try:
isdir = os.path.isdir(path) isdir = os.path.isdir(path)
except Exception: except Exception:

View File

@@ -4,10 +4,13 @@ import io
import numbers import numbers
import zlib import zlib
from ebook_converter.utils.logging import default_log from ebook_converter import logging
from ebook_converter import polyglot from ebook_converter import polyglot
LOG = logging.default_log
pdf_float = lambda x: f"{x:.1f}" pdf_float = lambda x: f"{x:.1f}"
EOL = b'\n' EOL = b'\n'
@@ -234,7 +237,7 @@ class Reference(object):
def current_log(newlog=None): def current_log(newlog=None):
if newlog: if newlog:
current_log.ans = newlog current_log.ans = newlog
return current_log.ans or default_log return current_log.ans or LOG
current_log.ans = None current_log.ans = None