I'm new to fabric. I'm trying to check if setkey is installed in the remote machine. For that I'm just trying to check its version number and if it returns an error then it will install the required package. The following is开发者_如何学JAVA the code
with settings(hide('stdout'), warn_only=True):
out = sudo('setkey -V', shell=False);
if out.failed:
print(red("* Setkey not installed. Installing"))
sudo(setkey_install)
However I'm getting a warning
Warning: sudo() encountered an error (return code 1) while executing 'setkey -V'
What could be the reason for this? Is there any other way to check if a package is installed?
I would use the *nix command which
to return the location of the setkey
(or nothing if it doesn't exist), with something like this:
with settings(hide('stdout'), warn_only=True):
if not run('which setkey'):
print(red("* Setkey not installed. Installing..."))
sudo(setkey_install)
Since run
returns the output of the command it's given you should be able to use the not
operator on it like this.
精彩评论