[pp:exec] use non-UNC path replacements (#8879)

provide '{_path_unc}' and '{_directory_unc}' replacement fields
This commit is contained in:
Mike Fährmann
2026-02-14 11:25:08 +01:00
parent d99c8c1320
commit 98eb857794
4 changed files with 32 additions and 19 deletions

View File

@@ -899,7 +899,8 @@ def build_parser():
action=AppendCommandAction, const={"name": "exec"},
help=("Execute CMD for each downloaded file. "
"Supported replacement fields are "
"{} or {_path}, {_directory}, {_filename}. "
"{} or {_path}, {_temppath}, {_directory}, {_filename}. "
"On Windows, use {_path_unc} or {_directory_unc} for UNC paths. "
"Example: --exec \"convert {} {}.png && rm {}\""),
)
postprocessor.add_argument(

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018-2023 Mike Fährmann
# Copyright 2018-2026 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
@@ -61,7 +61,8 @@ class ExecPP(PostProcessor):
def _prepare_cmd(self, cmd):
if isinstance(cmd, str):
self._sub = util.re(
r"\{(_directory|_filename|_(?:temp)?path|)\}").sub
r"(?i)\{(_directory(?:_unc)?|_filename"
r"|_(?:temp)?path(?:_unc)?|)\}").sub
return self.exec_string, cmd
else:
return self.exec_list, [formatter.parse(arg) for arg in cmd]
@@ -73,10 +74,13 @@ class ExecPP(PostProcessor):
if archive and archive.check(kwdict):
return
kwdict["_directory"] = pathfmt.realdirectory
kwdict["_directory"] = pathfmt.directory
kwdict["_filename"] = pathfmt.filename
kwdict["_temppath"] = pathfmt.temppath
kwdict["_path"] = pathfmt.realpath
kwdict["_path"] = pathfmt.path
if util.WINDOWS:
kwdict["_directory_unc"] = pathfmt.realdirectory
kwdict["_path_unc"] = pathfmt.realpath
args = [arg.format_map(kwdict) for arg in self.args]
args[0] = os.path.expanduser(args[0])
@@ -133,14 +137,17 @@ class ExecPP(PostProcessor):
)
def _replace(self, match):
name = match[1]
if name == "_directory":
return quote(self.pathfmt.realdirectory)
if name == "_filename":
return quote(self.pathfmt.filename)
if name == "_temppath":
return quote(self.pathfmt.temppath)
return quote(self.pathfmt.realpath)
attr = {
"" : "path",
"_path" : "path",
"_path_unc" : "realpath",
"_temppath" : "temppath",
"_temppath_unc" : "temppath",
"_directory" : "directory",
"_directory_unc": "realdirectory",
"_filename" : "filename",
}[match[1].lower()]
return quote(getattr(self.pathfmt, attr))
__postprocessor__ = ExecPP