擅长:python、mysql、java
<p>我就是这样做的。简而言之:如果设置了<a href="http://fabric.readthedocs.org/en/1.8/usage/env.html#password" rel="nofollow">^{<cd1>}</a>,fabric将使用它连接到<a href="http://fabric.readthedocs.org/en/1.8/usage/env.html#hosts" rel="nofollow">^{<cd2>}</a>中列出的服务器:</p>
<pre><code>from getpass import getpass
from fabric.api import env
# Setting env.hosts
env.hosts = ['someuser@someserver.com']
def deploy():
"""A deployment script"""
# Setting env.password with `getpass`
# See here for more: http://fabric.readthedocs.org/en/1.8/usage/env.html#password
env.password = getpass('Enter the password for %s: ' % env.hosts[0])
# The rest of the script follows...
</code></pre>