[pp:exec] support more replacement fields for '--exec' (#4633)

- {_directory}
- {_filename}
- {_path} (alias for {})
This commit is contained in:
Mike Fährmann
2023-10-09 12:50:10 +02:00
parent 9a008523ac
commit 67ba4ee842
4 changed files with 28 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ from .common import PostProcessor
from .. import util, formatter
import subprocess
import os
import re
if util.WINDOWS:
@@ -32,6 +33,7 @@ class ExecPP(PostProcessor):
args = options["command"]
if isinstance(args, str):
self.args = args
self._sub = re.compile(r"\{(_directory|_filename|_path|)\}").sub
execute = self.exec_string
else:
self.args = [formatter.parse(arg) for arg in args]
@@ -69,11 +71,8 @@ class ExecPP(PostProcessor):
if archive and archive.check(pathfmt.kwdict):
return
if pathfmt.realpath:
args = self.args.replace("{}", quote(pathfmt.realpath))
else:
args = self.args.replace("{}", quote(pathfmt.realdirectory))
self.pathfmt = pathfmt
args = self._sub(self._replace, self.args)
self._exec(args, True)
if archive:
@@ -90,5 +89,13 @@ class ExecPP(PostProcessor):
self.log.debug("Running '%s'", args)
subprocess.Popen(args, shell=shell)
def _replace(self, match):
name = match.group(1)
if name == "_directory":
return quote(self.pathfmt.realdirectory)
if name == "_filename":
return quote(self.pathfmt.filename)
return quote(self.pathfmt.realpath)
__postprocessor__ = ExecPP