add 'prepare()' step for post-processors

This allows post-processors to modify the destination path before
checking if a file already exists.
This commit is contained in:
Mike Fährmann
2018-10-18 22:32:03 +02:00
parent c9861ca812
commit d3d7f01543
5 changed files with 32 additions and 11 deletions

View File

@@ -32,13 +32,18 @@ class ClassifyPP(PostProcessor):
for ext in exts
}
def run(self, pathfmt):
def prepare(self, pathfmt):
ext = pathfmt.keywords["extension"]
if ext in self.mapping:
path = pathfmt.realdirectory + os.sep + self.mapping[ext]
pathfmt.realpath = path + os.sep + pathfmt.filename
os.makedirs(path, exist_ok=True)
self._dir = pathfmt.realdirectory + os.sep + self.mapping[ext]
pathfmt.realpath = self._dir + os.sep + pathfmt.filename
else:
self._dir = None
def run(self, pathfmt):
if self._dir:
os.makedirs(self._dir, exist_ok=True)
__postprocessor__ = ClassifyPP