make 'path' and 'keywords' available in logging messages

Wrap all loggers used by job, extractor, downloader, and postprocessor
objects into a (custom) LoggerAdapter that provides access to the
underlying job, extractor, pathfmt, and kwdict objects and their
properties.

__init__() signatures for all downloader and postprocessor classes have
been changed to take the current Job object as their first argument,
instead of the current extractor or pathfmt.

(#574, #575)
This commit is contained in:
Mike Fährmann
2020-05-18 01:35:53 +02:00
parent 846d3a2466
commit ece73b5b2a
17 changed files with 149 additions and 97 deletions

View File

@@ -9,7 +9,6 @@
"""Post-processing modules"""
import importlib
import logging
modules = [
"classify",
@@ -21,8 +20,6 @@ modules = [
"zip",
]
log = logging.getLogger("postprocessor")
def find(name):
"""Return a postprocessor class with the given name"""

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Mike Fährmann
# Copyright 2018-2020 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -22,8 +22,8 @@ class ClassifyPP(PostProcessor):
"Archives" : ("zip", "rar", "7z", "tar", "gz", "bz2"),
}
def __init__(self, pathfmt, options):
PostProcessor.__init__(self)
def __init__(self, job, options):
PostProcessor.__init__(self, job)
mapping = options.get("mapping", self.DEFAULT_MAPPING)
self.mapping = {

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018-2019 Mike Fährmann
# Copyright 2018-2020 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -8,15 +8,13 @@
"""Common classes and constants used by postprocessor modules."""
import logging
class PostProcessor():
"""Base class for postprocessors"""
def __init__(self):
def __init__(self, job):
name = self.__class__.__name__[:-2].lower()
self.log = logging.getLogger("postprocessor." + name)
self.log = job.get_logger("postprocessor." + name)
@staticmethod
def prepare(pathfmt):

View File

@@ -14,8 +14,8 @@ import os
class ComparePP(PostProcessor):
def __init__(self, pathfmt, options):
PostProcessor.__init__(self)
def __init__(self, job, options):
PostProcessor.__init__(self, job)
if options.get("action") == "enumerate":
self.run = self._run_enumerate
if options.get("shallow"):

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018-2019 Mike Fährmann
# Copyright 2018-2020 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -23,8 +23,8 @@ else:
class ExecPP(PostProcessor):
def __init__(self, pathfmt, options):
PostProcessor.__init__(self)
def __init__(self, job, options):
PostProcessor.__init__(self, job)
args = options["command"]
final = options.get("final", False)

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Mike Fährmann
# Copyright 2019-2020 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -15,8 +15,8 @@ import os
class MetadataPP(PostProcessor):
def __init__(self, pathfmt, options):
PostProcessor.__init__(self)
def __init__(self, job, options):
PostProcessor.__init__(self, job)
mode = options.get("mode", "json")
if mode == "custom":

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Mike Fährmann
# Copyright 2019-2020 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -14,8 +14,8 @@ from ..text import parse_int
class MtimePP(PostProcessor):
def __init__(self, pathfmt, options):
PostProcessor.__init__(self)
def __init__(self, job, options):
PostProcessor.__init__(self, job)
self.key = options.get("key", "date")
def run(self, pathfmt):

View File

@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Mike Fährmann
# Copyright 2018-2020 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
"""Convert pixiv ugoira to webm"""
"""Convert Pixiv Ugoira to WebM"""
from .common import PostProcessor
from .. import util
@@ -19,8 +19,8 @@ import os
class UgoiraPP(PostProcessor):
def __init__(self, pathfmt, options):
PostProcessor.__init__(self)
def __init__(self, job, options):
PostProcessor.__init__(self, job)
self.extension = options.get("extension") or "webm"
self.args = options.get("ffmpeg-args") or ()
self.twopass = options.get("ffmpeg-twopass", False)

View File

@@ -22,8 +22,8 @@ class ZipPP(PostProcessor):
"lzma" : zipfile.ZIP_LZMA,
}
def __init__(self, pathfmt, options):
PostProcessor.__init__(self)
def __init__(self, job, options):
PostProcessor.__init__(self, job)
self.delete = not options.get("keep-files", False)
ext = "." + options.get("extension", "zip")
algorithm = options.get("compression", "store")
@@ -33,7 +33,7 @@ class ZipPP(PostProcessor):
algorithm)
algorithm = "store"
self.path = pathfmt.realdirectory
self.path = job.pathfmt.realdirectory
args = (self.path[:-1] + ext, "a",
self.COMPRESSION_ALGORITHMS[algorithm], True)