summaryrefslogtreecommitdiffstats
path: root/gallery_dl/postprocessor/exec.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2020-12-13 23:07:42 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2020-12-13 23:07:42 -0500
commit8f7c87a2697113134c311aaeafd9c919555a2741 (patch)
tree4ff7316ac1570683b3c968fd30d044925e47a2a5 /gallery_dl/postprocessor/exec.py
parent143723944033d7a6593d57bd1cf6ae97713b6ce7 (diff)
New upstream version 1.16.0.upstream/1.16.0
Diffstat (limited to 'gallery_dl/postprocessor/exec.py')
-rw-r--r--gallery_dl/postprocessor/exec.py72
1 files changed, 38 insertions, 34 deletions
diff --git a/gallery_dl/postprocessor/exec.py b/gallery_dl/postprocessor/exec.py
index cbe51ae..205f42e 100644
--- a/gallery_dl/postprocessor/exec.py
+++ b/gallery_dl/postprocessor/exec.py
@@ -24,54 +24,58 @@ class ExecPP(PostProcessor):
def __init__(self, job, options):
PostProcessor.__init__(self, job)
- args = options["command"]
- final = options.get("final", False)
+ if options.get("async", False):
+ self._exec = self._exec_async
+
+ args = options["command"]
if isinstance(args, str):
- if final:
- self._format = self._format_args_directory
- else:
- self._format = self._format_args_path
if "{}" not in args:
args += " {}"
self.args = args
- self.shell = True
+ execute = self.exec_string
else:
- self._format = self._format_args_list
self.args = [util.Formatter(arg) for arg in args]
- self.shell = False
-
- if final:
- self.run_after = PostProcessor.run_after
- else:
- self.run_final = PostProcessor.run_final
-
- if options.get("async", False):
- self._exec = self._exec_async
+ execute = self.exec_list
+
+ events = options.get("event")
+ if events is None:
+ events = ("after",)
+ if options.get("final"):
+ self.log.warning("'final' is deprecated, "
+ "use '\"event\": \"finalize\"' instead")
+ events = ("finalize",)
+ elif isinstance(events, str):
+ events = events.split(",")
+ for event in events:
+ job.hooks[event].append(execute)
+
+ def exec_list(self, pathfmt, status=None):
+ if status:
+ return
- def run_after(self, pathfmt):
- self._exec(self._format(pathfmt))
-
- def run_final(self, pathfmt, status):
- if status == 0:
- self._exec(self._format(pathfmt))
-
- def _format_args_path(self, pathfmt):
- return self.args.replace("{}", quote(pathfmt.realpath))
-
- def _format_args_directory(self, pathfmt):
- return self.args.replace("{}", quote(pathfmt.realdirectory))
-
- def _format_args_list(self, pathfmt):
kwdict = pathfmt.kwdict
kwdict["_directory"] = pathfmt.realdirectory
kwdict["_filename"] = pathfmt.filename
kwdict["_path"] = pathfmt.realpath
- return [arg.format_map(kwdict) for arg in self.args]
- def _exec(self, args):
+ args = [arg.format_map(kwdict) for arg in self.args]
+ self._exec(args, False)
+
+ def exec_string(self, pathfmt, status=None):
+ if status:
+ return
+
+ if status is None and pathfmt.realpath:
+ args = self.args.replace("{}", quote(pathfmt.realpath))
+ else:
+ args = self.args.replace("{}", quote(pathfmt.realdirectory))
+
+ self._exec(args, True)
+
+ def _exec(self, args, shell):
self.log.debug("Running '%s'", args)
- retcode = subprocess.Popen(args, shell=self.shell).wait()
+ retcode = subprocess.Popen(args, shell=shell).wait()
if retcode:
self.log.warning(
"Executing '%s' returned with non-zero exit status (%d)",