[pp:exec] implement 'commands' option

to run multiple commands in succession
and stopping if one fails
This commit is contained in:
Mike Fährmann
2025-06-13 20:19:01 +02:00
parent 9d3cf67f3e
commit fa1fc39a36
3 changed files with 93 additions and 16 deletions

View File

@@ -10,7 +10,7 @@
import os
import sys
import unittest
from unittest.mock import Mock, mock_open, patch
from unittest.mock import Mock, mock_open, patch, call
import shutil
import logging
@@ -233,6 +233,38 @@ class ExecTest(BasePostprocessorTest):
shell=False,
)
def test_command_many(self):
self._create({
"commands": [
"echo {} {_path} {_directory} {_filename} && rm {};",
["~/script.sh", "{category}", "\fE _directory.upper()"],
]
})
with patch("gallery_dl.util.Popen") as p:
i = Mock()
i.wait.return_value = 0
p.return_value = i
self._trigger(("after",))
self.assertEqual(p.call_args_list, [
call(
"echo {0} {0} {1} {2} && rm {0};".format(
self.pathfmt.realpath,
self.pathfmt.realdirectory,
self.pathfmt.filename),
shell=True,
),
call(
[
os.path.expanduser("~/script.sh"),
self.pathfmt.kwdict["category"],
self.pathfmt.realdirectory.upper(),
],
shell=False,
),
])
def test_command_returncode(self):
self._create({
"command": "echo {}",
@@ -944,8 +976,8 @@ class ZipTest(BasePostprocessorTest):
self._trigger(("finalize",))
self.assertEqual(pp.zfile.write.call_count, 3)
for call in pp.zfile.write.call_args_list:
args, kwargs = call
for call_args in pp.zfile.write.call_args_list:
args, kwargs = call_args
self.assertEqual(len(args), 2)
self.assertEqual(len(kwargs), 0)
self.assertEqual(args[0], self.pathfmt.temppath)