Change execute('start')
to execute(start)
.
I didn't find out why pass a taskname to execute did not work, but there is a workaround:
import fabfile
execute(getattr(fabfile, 'start'))
Update:
After reading a bit code and doing some test of fabric, I think execute('task_name')
can only be used when fabric tasks are loaded. By default you can use it in the fabfile.py like this:
@task
def task1():
#do task1
@task
def task2():
#do task2
@task
def task3():
#do task1 and task2
execute('task1')
execute('task2')
Then you can use fab task3
to execute task1
and task2
together. But till now, I am still using fabric a tool.
Update again :-)
Then I read a bit code of fabric and found that
use fabric as a tool will call fabric.main.main
which invokes fabric.main.load_fabfile
to load tasks from the fabfile.
Since you use python main.py
to run your script, fab tasks are not loaded even if you imported fabfile. So I add a bit code to you main.py
:
docstring, callables, default = load_fabfile('fabfile.py')
state.commands.update(callables)
And now, execute('start')
works exactly as you wanted.