Skip to content

Commit e589d6f

Browse files
committed
[pp:exec] add 'verbose' option (#7743)
1 parent bb16e03 commit e589d6f

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

docs/configuration.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8018,6 +8018,17 @@ Description
80188018
to have it call ``setsid()``.
80198019

80208020

8021+
exec.verbose
8022+
------------
8023+
Type
8024+
``bool``
8025+
Default
8026+
``true``
8027+
Description
8028+
Include `command <exec.command_>`__
8029+
arguments in logging messages.
8030+
8031+
80218032
hash.chunk-size
80228033
---------------
80238034
Type

gallery_dl/postprocessor/exec.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def quote(s):
2222
from shlex import quote
2323

2424

25+
def trim(args):
26+
return (args.partition(" ") if isinstance(args, str) else args)[0]
27+
28+
2529
class ExecPP(PostProcessor):
2630

2731
def __init__(self, job, options):
@@ -35,6 +39,7 @@ def __init__(self, job, options):
3539
if options.get("async", False):
3640
self._exec = self._popen
3741

42+
self.verbose = options.get("verbose", True)
3843
self.session = False
3944
self.creationflags = 0
4045
if options.get("session"):
@@ -115,11 +120,11 @@ def exec_many(self, pathfmt):
115120
def _exec(self, args, shell):
116121
if retcode := self._popen(args, shell).wait():
117122
self.log.warning("'%s' returned with non-zero exit status (%d)",
118-
args, retcode)
123+
args if self.verbose else trim(args), retcode)
119124
return retcode
120125

121126
def _popen(self, args, shell):
122-
self.log.debug("Running '%s'", args)
127+
self.log.debug("Running '%s'", args if self.verbose else trim(args))
123128
return util.Popen(
124129
args,
125130
shell=shell,

test/test_postprocessor.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,40 @@ def test_archive(self):
374374
m_aa.assert_called_once_with(self.pathfmt.kwdict)
375375
m_ac.assert_called_once()
376376

377+
def test_verbose_string(self):
378+
self._create({
379+
"command": "echo foo bar",
380+
"verbose": False,
381+
})
382+
383+
with patch("gallery_dl.util.Popen") as p, \
384+
self.assertLogs(level=10) as log_info:
385+
i = Mock()
386+
i.wait.return_value = 123
387+
p.return_value = i
388+
self._trigger(("after",))
389+
390+
msg = "DEBUG:postprocessor.exec:Running 'echo'"
391+
self.assertEqual(log_info.output[0], msg)
392+
self.assertIn("'echo' returned with non-zero ", log_info.output[1])
393+
394+
def test_verbose_list(self):
395+
self._create({
396+
"command": ["echo", "foo", "bar"],
397+
"verbose": False,
398+
})
399+
400+
with patch("gallery_dl.util.Popen") as p, \
401+
self.assertLogs(level=10) as log_info:
402+
i = Mock()
403+
i.wait.return_value = 123
404+
p.return_value = i
405+
self._trigger(("after",))
406+
407+
msg = "DEBUG:postprocessor.exec:Running 'echo'"
408+
self.assertEqual(log_info.output[0], msg)
409+
self.assertIn("'echo' returned with non-zero ", log_info.output[1])
410+
377411

378412
class HashTest(BasePostprocessorTest):
379413

0 commit comments

Comments
 (0)