[postprocessor:exec] run after file moved to target location

(#421)
This commit is contained in:
Mike Fährmann
2019-10-06 21:58:00 +02:00
parent 35958bebd4
commit 03bc8adfc7
3 changed files with 10 additions and 4 deletions

View File

@@ -237,6 +237,9 @@ class DownloadJob(Job):
self.out.success(pathfmt.path, 0)
if archive:
archive.add(keywords)
if postprocessors:
for pp in postprocessors:
pp.run_after(pathfmt)
self._skipcnt = 0
def handle_urllist(self, urls, keywords):

View File

@@ -21,6 +21,9 @@ class PostProcessor():
def run(self, pathfmt):
"""Execute the postprocessor for a file"""
def run_after(self, pathfmt):
"""Execute postprocessor after moving a file to its target location"""
def finalize(self):
"""Cleanup"""

View File

@@ -41,25 +41,25 @@ class ExecPP(PostProcessor):
if options.get("async", False):
self._exec = self._exec_async
def run(self, pathfmt):
def run_after(self, pathfmt):
self._exec(self._format(pathfmt))
def _format_args_string(self, pathfmt):
return self.args.replace("{}", quote(pathfmt.temppath))
return self.args.replace("{}", quote(pathfmt.realpath))
def _format_args_list(self, pathfmt):
kwdict = pathfmt.kwdict
kwdict["_directory"] = pathfmt.realdirectory
kwdict["_filename"] = pathfmt.filename
kwdict["_temppath"] = pathfmt.temppath
kwdict["_path"] = pathfmt.realpath
return [arg.format_map(kwdict) for arg in self.args]
def _exec(self, args):
self.log.debug("Running '%s'", args)
retcode = subprocess.Popen(args, shell=self.shell).wait()
if retcode:
self.log.warning(
"executing '%s' returned with non-zero exit status (%d)",
"Executing '%s' returned with non-zero exit status (%d)",
" ".join(args) if isinstance(args, list) else args, retcode)
def _exec_async(self, args):