support 'filter' option for post processors (#1460)

This commit is contained in:
Mike Fährmann
2021-06-04 18:08:08 +02:00
parent 4cf40434d7
commit 3cbbefd4ed
10 changed files with 47 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018-2020 Mike Fährmann
# Copyright 2018-2021 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
@@ -31,9 +31,8 @@ class ClassifyPP(PostProcessor):
for directory, exts in mapping.items()
for ext in exts
}
job.hooks["prepare"].append(self.prepare)
job.hooks["file"].append(self.move)
job.register_hooks(
{"prepare": self.prepare, "file": self.move}, options)
def prepare(self, pathfmt):
ext = pathfmt.extension

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Mike Fährmann
# Copyright 2020-2021 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
@@ -18,11 +18,12 @@ class ComparePP(PostProcessor):
PostProcessor.__init__(self, job)
if options.get("shallow"):
self._compare = self._compare_size
job.hooks["file"].append(
job.register_hooks({"file": (
self.enumerate
if options.get("action") == "enumerate" else
self.compare
)
)}, options)
def compare(self, pathfmt):
try:

View File

@@ -41,8 +41,7 @@ class ExecPP(PostProcessor):
events = ("after",)
elif isinstance(events, str):
events = events.split(",")
for event in events:
job.hooks[event].append(execute)
job.register_hooks({event: execute for event in events}, options)
def exec_list(self, pathfmt, status=None):
if status:

View File

@@ -57,8 +57,7 @@ class MetadataPP(PostProcessor):
events = ("file",)
elif isinstance(events, str):
events = events.split(",")
for event in events:
job.hooks[event].append(self.run)
job.register_hooks({event: self.run for event in events}, options)
def run(self, pathfmt):
directory = self._directory(pathfmt)

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2019-2020 Mike Fährmann
# Copyright 2019-2021 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
@@ -17,7 +17,7 @@ class MtimePP(PostProcessor):
def __init__(self, job, options):
PostProcessor.__init__(self, job)
self.key = options.get("key", "date")
job.hooks["file"].append(self.run)
job.register_hooks({"file": self.run}, options)
def run(self, pathfmt):
mtime = pathfmt.kwdict.get(self.key)

View File

@@ -55,8 +55,8 @@ class UgoiraPP(PostProcessor):
else:
self.prevent_odd = False
job.hooks["prepare"].append(self.prepare)
job.hooks["file"].append(self.convert)
job.register_hooks(
{"prepare": self.prepare, "file": self.convert}, options)
def prepare(self, pathfmt):
self._frames = None

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018-2020 Mike Fährmann
# Copyright 2018-2021 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
@@ -38,9 +38,11 @@ class ZipPP(PostProcessor):
self.args = (self.path[:-1] + ext, "a",
self.COMPRESSION_ALGORITHMS[algorithm], True)
job.hooks["file"].append(
self.write_safe if options.get("mode") == "safe" else self.write)
job.hooks["finalize"].append(self.finalize)
job.register_hooks({
"file":
self.write_safe if options.get("mode") == "safe" else self.write,
"finalize": self.finalize,
}, options)
def write(self, pathfmt, zfile=None):
# 'NameToInfo' is not officially documented, but it's available