Reputation: 15
I am using Python doit and would like to dynamically generate actions. The following code creates a list of commands that I would like doit to execute:
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,
}
The only issue is that doit only runs the first element in the list:
"rsync -a a ../package"
And I would like it to do the following:
"rsync -a a ../package"
"rsync -a b ../package"
"rsync -a c ../package"
I have tried using 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 but feel like I am missing something.
Upvotes: 0
Views: 130
Reputation: 3170
It seems your problem is that you are adding a list inside another list. Try:
'actions': ["mkdir -p ../package"] + create_cmd_string,
Upvotes: 0