Skip to content

Commit

Permalink
Changing logging module location.
Browse files Browse the repository at this point in the history
  • Loading branch information
gryf committed Jun 28, 2021
1 parent b574357 commit 3f57198
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion ebook_converter/customize/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def convert(self, stream, options, file_ext, log, accelerators):
:param file_ext: The extension (without the .) of the input file. It
is guaranteed to be one of the `file_types` supported
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.
:param accelarators: A dictionary of various information that the input
plugin can get easily that would speed up the
Expand Down
7 changes: 4 additions & 3 deletions ebook_converter/ebooks/conversion/plugins/snb_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ class OptionValues(object):
opts.output_profile = HanlinV3Output(None)

html_preprocessor = HTMLPreProcessor(None, None, opts)
from ebook_converter.utils.logging import default_log
oeb = OEBBook(default_log, html_preprocessor)
from ebook_converter import logging
oeb = OEBBook(logging.default_log, html_preprocessor)
reader = OEBReader
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)
7 changes: 5 additions & 2 deletions ebook_converter/ebooks/conversion/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import re
from math import ceil
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


LOG = logging.default_log


class HeuristicProcessor(object):

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.found_indents = 0
self.extra_opts = extra_opts
Expand Down
7 changes: 5 additions & 2 deletions ebook_converter/ebooks/docx/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
from ebook_converter.ebooks.docx.names import DOCXNamespace
from ebook_converter.ptempfile import PersistentTemporaryDirectory
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


LOG = logging.default_log


# Read metadata {{{
def read_doc_props(raw, mi, XPath):
root = etree.fromstring(raw)
Expand Down Expand Up @@ -86,7 +89,7 @@ def __init__(self, path_or_stream, log=None, extract=True):
if not hasattr(path_or_stream, 'read'):
stream = open(path_or_stream, 'rb')
self.name = getattr(stream, 'name', None) or '<stream>'
self.log = log or default_log
self.log = log or LOG
if extract:
self.extract(stream)
else:
Expand Down
7 changes: 4 additions & 3 deletions ebook_converter/ebooks/docx/to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,11 @@ def process_run(run):

if __name__ == '__main__':
import shutil
from ebook_converter.utils.logging import default_log
default_log.filter_level = default_log.DEBUG
from ebook_converter import logging
logging.default_log.filter_level = logging.default_log.DEBUG
dest_dir = os.path.join(os.getcwd(), 'docx_input')
if os.path.exists(dest_dir):
shutil.rmtree(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)()
5 changes: 3 additions & 2 deletions ebook_converter/ebooks/htmlz/oeb2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
from ebook_converter.ebooks.oeb import parse_utils
from ebook_converter.ebooks.oeb.stylizer import Stylizer
from ebook_converter.utils import entities
from ebook_converter.utils.logging import default_log
from ebook_converter import logging
from ebook_converter import polyglot


SELF_CLOSING_TAGS = {'area', 'base', 'basefont', 'br', 'hr', 'input', 'img',
'link', 'meta'}
LOG = logging.default_log


class OEB2HTML(object):
Expand All @@ -34,7 +35,7 @@ class OEB2HTML(object):
"""

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.images = {}

Expand Down
18 changes: 8 additions & 10 deletions ebook_converter/ebooks/mobi/tweak.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ebook_converter.ebooks.mobi import MobiError
from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader
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.mobi.reader.mobi8 import Mobi8Reader
from ebook_converter.ebooks.conversion.plumber import Plumber, create_oebbook
Expand All @@ -14,9 +14,7 @@
from ebook_converter.utils.ipc.simple_worker import fork_job


__license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
LOG = logging.default_log


class BadFormat(ValueError):
Expand All @@ -25,10 +23,10 @@ class BadFormat(ValueError):

def do_explode(path, dest):
with open(path, 'rb') as stream:
mr = MobiReader(stream, default_log, None, None)
mr = MobiReader(stream, LOG, None, None)

with directory.CurrentDir(dest):
mr = Mobi8Reader(mr, default_log)
mr = Mobi8Reader(mr, LOG)
opf = os.path.abspath(mr())
try:
os.remove('debug-raw.html')
Expand All @@ -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.')

try:
header = MetadataHeader(stream, default_log)
header = MetadataHeader(stream, LOG)
except MobiError:
raise BadFormat('This is not a MOBI file.')

Expand Down Expand Up @@ -85,15 +83,15 @@ def set_cover(oeb):


def do_rebuild(opf, dest_path):
plumber = Plumber(opf, dest_path, default_log)
plumber = Plumber(opf, dest_path, LOG)
plumber.setup_options()
inp = plugin_for_input_format('azw3')
outp = plugin_for_output_format('azw3')

plumber.opts.mobi_passthrough = True
oeb = create_oebbook(default_log, opf, plumber.opts)
oeb = create_oebbook(LOG, opf, plumber.opts)
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):
Expand Down
11 changes: 6 additions & 5 deletions ebook_converter/ebooks/oeb/polish/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
from ebook_converter.utils import directory
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.logging import default_log
from ebook_converter import logging
from ebook_converter.utils.zipfile import ZipFile

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'}
null = object()
LOG = logging.default_log


class CSSPreProcessor(cssp):
Expand Down Expand Up @@ -1391,10 +1392,10 @@ def do_explode(path, dest):
from ebook_converter.ebooks.mobi.reader.mobi6 import MobiReader
from ebook_converter.ebooks.mobi.reader.mobi8 import Mobi8Reader
with open(path, 'rb') as stream:
mr = MobiReader(stream, default_log, None, None)
mr = MobiReader(stream, LOG, None, None)

with directory.CurrentDir(dest):
mr = Mobi8Reader(mr, default_log, for_tweak=True)
mr = Mobi8Reader(mr, LOG, for_tweak=True)
opf = os.path.abspath(mr())
obfuscated_fonts = mr.encrypted_fonts

Expand Down Expand Up @@ -1455,7 +1456,7 @@ def __init__(self, pathtoazw3, log, clone_data=None, tdir=None):
'file.')

try:
header = MetadataHeader(stream, default_log)
header = MetadataHeader(stream, LOG)
except MobiError:
raise InvalidMobi('This is not a MOBI file.')

Expand Down Expand Up @@ -1514,7 +1515,7 @@ def names_that_must_not_be_changed(self):

def get_container(path, log=None, tdir=None, tweak_mode=False):
if log is None:
log = default_log
log = LOG
try:
isdir = os.path.isdir(path)
except Exception:
Expand Down
7 changes: 5 additions & 2 deletions ebook_converter/ebooks/pdf/render/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import numbers
import zlib

from ebook_converter.utils.logging import default_log
from ebook_converter import logging
from ebook_converter import polyglot


LOG = logging.default_log


pdf_float = lambda x: f"{x:.1f}"

EOL = b'\n'
Expand Down Expand Up @@ -234,7 +237,7 @@ def __str__(self):
def current_log(newlog=None):
if newlog:
current_log.ans = newlog
return current_log.ans or default_log
return current_log.ans or LOG


current_log.ans = None
File renamed without changes.

0 comments on commit 3f57198

Please sign in to comment.