我是Python和Fabric的新手,使用的是Fabric==1.10.1和Python2.7.6。我不明白fabric.api和fabric.operations调用之间的区别,它们似乎都在做同样的事情。我应该在fabfile中使用哪一个?我注意到的一件事是,当我执行fabric.api.reboot()时,它确实会显示消息,
[127.0.0.1] out: Broadcast message from vagrant@localhost.localdomain
[127.0.0.1] out:
[127.0.0.1] out: (/dev/pts/0) at 17:39 ...
[127.0.0.1] out:
[127.0.0.1] out:
[127.0.0.1] out:
[127.0.0.1] out:
[127.0.0.1] out: The system is going down for reboot NOW!
[127.0.0.1] out:但是当我使用fabric.operations.reboot()时,它不会显示任何消息。
更新:实际上,似乎是fabric.operations.reboot()和fabric.api.reboot()产生了这个消息。
发布于 2015-08-19 09:10:57
您可以使用这两种方法中的任何一种,但fabric.api是更好的选择。这是因为为了简单起见,它是导入其他fabric模块的地方。请看这里:
$ cat fabric/api.py (env: selenium)
"""
Non-init module for doing convenient * imports from.
Necessary because if we did this in __init__, one would be unable to import
anything else inside the package -- like, say, the version number used in
setup.py -- without triggering loads of most of the code. Which doesn't work so
well when you're using setup.py to install e.g. ssh!
"""
from fabric.context_managers import (cd, hide, settings, show, path, prefix,
lcd, quiet, warn_only, remote_tunnel, shell_env)
from fabric.decorators import (hosts, roles, runs_once, with_settings, task,
serial, parallel)
from fabric.operations import (require, prompt, put, get, run, sudo, local,
reboot, open_shell)
from fabric.state import env, output
from fabric.utils import abort, warn, puts, fastprint
from fabric.tasks import executefabric.api已经在为您导入fabric.operations.reboot。
https://stackoverflow.com/questions/30415840
复制相似问题