Python 必须动态动作

Python doit dynamic actions

我正在使用 Python doit 并希望动态生成操作。以下代码创建了我想要执行的命令列表:

dirs = ['a','b','c']

def task_build():

    def create_cmd_string(directories=dirs):
        cmds = []
        for dir in directories:
            cmds.append(f"rsync -a {dir} ../package")
        return cmds

    return {
        'actions': [
            "mkdir -p ../package",
            create_cmd_string,
        ],
        'verbosity': 2,
    }

唯一的问题是 doit 只运行列表中的第一个元素:

"rsync -a a ../package"

我希望它执行以下操作:

"rsync -a a ../package"
"rsync -a b ../package"
"rsync -a c ../package"

我试过使用CmdAction and passing in different data types but neither of these methods worked. I'm thinking the next solution would be to create dynamic subtasks,但感觉好像遗漏了什么。

您的问题似乎是您要在另一个列表添加一个列表。 尝试:

'actions': ["mkdir -p ../package"] + create_cmd_string,