是的, 我知道使用 fab 能执行 fabfiles , 但我想通过 python 直接运行 fab task, 而不是通过 fab, 请问该怎么做?
光阴似箭催人老,日月如移越少年。
The solution has been found, execute(fab_fun) can be run directly
Encapsulate it into a new script
Same as above, encapsulate the fab command into a script
test.py script content
#!/usr/bin/env python import subprocess p = subprocess.Popen("/usr/bin/fab uname_a",shell=True) p.wait()
fabfile.py content:
#!/usr/bin/env python from fabric.api import * from fabric.colors import red env.abort_exception = True def uname_a(): run("uname -a")
Originally, fab uname_a was executed to execute the fab command. Now use python test.py
The solution has been found, execute(fab_fun) can be run directly
Encapsulate it into a new script
Same as above, encapsulate the fab command into a script
test.py script content
fabfile.py content:
Originally, fab uname_a was executed to execute the fab command. Now use python test.py