I’ve been playing with Fabric.
With a hello world program:
def hello(name="world"):
print("hello %s!" % name)
if __name__ == '__main__':
import sys
from fabric.main import main
sys.argv = ['fab', '-f', __file__,] + sys.argv[1:]
main()
I can pass the argument hello:name=quanta and get the “hello quanta! result.
But with a below script:
from fabric.api import run
def hostname(host="localhost"):
run("hostname")
if __name__ == '__main__':
import sys
from fabric.main import main
sys.argv = ['fab', '-f', __file__,] + sys.argv[1:]
main()
I got the errors:
Fatal error: Command(s) not found:
hostnameAborting.
when passing hostname:host=192.168.3.118 as a argument within PyDev.
It’s working fine from the command line:
$ fab -f hostname.py hostname:host=192.168.3.118
[192.168.3.118] Executing task 'hostname'
[192.168.3.118] run: hostname
[192.168.3.118] out: SVR040-3118.localdomain
[192.168.3.118] out:
Done.
Disconnecting from 192.168.3.118... done.
It’s also happen with the env dictionary, something like this:
from fabric.api import run, env
env.hosts = ['192.168.3.118', '192.168.6.142']
def hostname():
run("hostname")
if __name__ == '__main__':
import sys
from fabric.main import main
sys.argv = ['fab', '-f', __file__,] + sys.argv[1:]
main()
although running it from the command line gets the expected results:
$ fab -f hostname.py hostname
[192.168.3.118] Executing task 'hostname'
[192.168.3.118] run: hostname
[192.168.3.118] out: SVR040-3118.localdomain
[192.168.3.118] out:
[192.168.6.142] Executing task 'hostname'
[192.168.6.142] run: hostname
[192.168.6.142] out: SVR040-6142
[192.168.6.142] out:
Done.
Disconnecting from 192.168.6.142... done.
Disconnecting from 192.168.3.118... done.
Sorry, my silly error.
I’m a Eclipse newcomer.
My source code structure is something like this:
Every Python files have own Run configuration. When I open the
hostname.pyfile and click on the play button (NOT the down arrow), it is actually running with thehelloconfiguration, this is reason for the above errors.To create a new Python run:
right click on the file -> Run As -> Run Configurations -> right click on Python Run -> new -> naming it, chose the right Project and Main Module -> switch to Arguments tab -> Set the ${string_prompt} for Program Arguments if you want -> Apply and Run.
For the later run, you can simply chose the right configuration from the down arrow (beside the play button).