[pp:exec] add 'verbose' option (#7743)
This commit is contained in:
@@ -8018,6 +8018,17 @@ Description
|
||||
to have it call ``setsid()``.
|
||||
|
||||
|
||||
exec.verbose
|
||||
------------
|
||||
Type
|
||||
``bool``
|
||||
Default
|
||||
``true``
|
||||
Description
|
||||
Include `command <exec.command_>`__
|
||||
arguments in logging messages.
|
||||
|
||||
|
||||
hash.chunk-size
|
||||
---------------
|
||||
Type
|
||||
|
||||
@@ -22,6 +22,10 @@ else:
|
||||
from shlex import quote
|
||||
|
||||
|
||||
def trim(args):
|
||||
return (args.partition(" ") if isinstance(args, str) else args)[0]
|
||||
|
||||
|
||||
class ExecPP(PostProcessor):
|
||||
|
||||
def __init__(self, job, options):
|
||||
@@ -35,6 +39,7 @@ class ExecPP(PostProcessor):
|
||||
if options.get("async", False):
|
||||
self._exec = self._popen
|
||||
|
||||
self.verbose = options.get("verbose", True)
|
||||
self.session = False
|
||||
self.creationflags = 0
|
||||
if options.get("session"):
|
||||
@@ -115,11 +120,11 @@ class ExecPP(PostProcessor):
|
||||
def _exec(self, args, shell):
|
||||
if retcode := self._popen(args, shell).wait():
|
||||
self.log.warning("'%s' returned with non-zero exit status (%d)",
|
||||
args, retcode)
|
||||
args if self.verbose else trim(args), retcode)
|
||||
return retcode
|
||||
|
||||
def _popen(self, args, shell):
|
||||
self.log.debug("Running '%s'", args)
|
||||
self.log.debug("Running '%s'", args if self.verbose else trim(args))
|
||||
return util.Popen(
|
||||
args,
|
||||
shell=shell,
|
||||
|
||||
@@ -374,6 +374,40 @@ class ExecTest(BasePostprocessorTest):
|
||||
m_aa.assert_called_once_with(self.pathfmt.kwdict)
|
||||
m_ac.assert_called_once()
|
||||
|
||||
def test_verbose_string(self):
|
||||
self._create({
|
||||
"command": "echo foo bar",
|
||||
"verbose": False,
|
||||
})
|
||||
|
||||
with patch("gallery_dl.util.Popen") as p, \
|
||||
self.assertLogs(level=10) as log_info:
|
||||
i = Mock()
|
||||
i.wait.return_value = 123
|
||||
p.return_value = i
|
||||
self._trigger(("after",))
|
||||
|
||||
msg = "DEBUG:postprocessor.exec:Running 'echo'"
|
||||
self.assertEqual(log_info.output[0], msg)
|
||||
self.assertIn("'echo' returned with non-zero ", log_info.output[1])
|
||||
|
||||
def test_verbose_list(self):
|
||||
self._create({
|
||||
"command": ["echo", "foo", "bar"],
|
||||
"verbose": False,
|
||||
})
|
||||
|
||||
with patch("gallery_dl.util.Popen") as p, \
|
||||
self.assertLogs(level=10) as log_info:
|
||||
i = Mock()
|
||||
i.wait.return_value = 123
|
||||
p.return_value = i
|
||||
self._trigger(("after",))
|
||||
|
||||
msg = "DEBUG:postprocessor.exec:Running 'echo'"
|
||||
self.assertEqual(log_info.output[0], msg)
|
||||
self.assertIn("'echo' returned with non-zero ", log_info.output[1])
|
||||
|
||||
|
||||
class HashTest(BasePostprocessorTest):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user