这与此处的这个问题有关,但略有不同:我需要 Fabric 将任意字符串传递给远程 shell,而不是只传递“是”或“否”。
例如,如果远程 shell 提示“你叫什么名字?” 然后我需要先喂它,最后喂它。
澄清:我知道我说的是任意输入,但是当我尝试执行 git pull 时,我真的想将它用于 SSH 密钥 passwd 提示。
更新 #1:得到 Jeff Forcier @bitprophet 的回复
这与此处的这个问题有关,但略有不同:我需要 Fabric 将任意字符串传递给远程 shell,而不是只传递“是”或“否”。
例如,如果远程 shell 提示“你叫什么名字?” 然后我需要先喂它,最后喂它。
澄清:我知道我说的是任意输入,但是当我尝试执行 git pull 时,我真的想将它用于 SSH 密钥 passwd 提示。
更新 #1:得到 Jeff Forcier @bitprophet 的回复
我已经在邮件列表中为 fabric 中的这个特性提出了一个 API,最后我自己写了一些东西:
from fexpect import expect, expecting, run
prompts = []
prompts += expect('What is your name?','John')
prompts += expect('Where do you live?','New York')
with expecting(prompts):
run('command')
Fabric 1.0 最终支持与远程服务器的交互。有关详细信息,请参阅此页面。
也许看看pexpect
我已经建立了一个名为 project_name/.git 的 git 原始存储库。
ssh to the server, (entering ssh passwords or passphrases as I go)
mkdir project_name
cd project_name
git init
touch fabfile.py
git add fabfile.py
git commit -a -m "almost empty"
git checkout -b web
我离开分支网络签出。回到本地机器。
我通过克隆从服务器中提取,并将我的项目目录内容添加到本地 repo 的分支 master 中。仍然不使用结构,只是进行设置,尽管我想这些步骤也可以自动化,而且它们都不需要另一个 ssh 密码。
cd /path/to/project_name/..
git clone ssh://joe@some_server.com/var/web/project_name/.git
cd project_name
gvim fabfile.py
git add fabfile.py
git commit -a -m "fabfile edits"
现在我开始使用织物。下面是从我的 fabfile 中摘录的,用于管理 git 标签和分支:
#Usage: fab committag brpush | fab committag push | fab push | fab tag
def committag():
"""commit chgs, tag new commit, push tags to server."""
prompt('commit descr: ', 'COM_MSG', default='new stuff')
prompt('commit name: ', 'COM_NAME', default='0.0.1')
local('git commit -a -m "%(COM_MSG)s"' % env)
local('sleep 1')
local('git tag -u "John Griessen" -m "%(COM_MSG)s" %(COM_NAME)s' % env)
local('sleep 1')
local('git push origin --tags') #pushes local tags
def brpush():
"""create a new branch, default COM_NAME, then push to server."""
prompt('new branch name: ', 'BR_NAME', default= '%(COM_NAME)s' % env)
local('git checkout -b %(BR_NAME)s' % env)
local('sleep 2')
local('git checkout master')
local('git push origin --tags') #pushes local tags
local('git push --all origin') #pushes local master and branches
def push():
"""Push existing tags and changes to server."""
local('git push origin --tags') #pushes local tags
local('git push --all origin') #pushes local master and branches
def tag(): #Call this from committag()
"""create a gpg signed tag on the local git repo tag from prompted name ."""
prompt('tag descr: ', 'TAG_MSG', default='0.0.1')
prompt('tag name: ', 'TAG_NAME', default='0.0.1')
local('git tag -u "John Griessen" -m "%(TAG_MSG)s" %(TAG_NAME)s' % env)
要使用上面的 fabfile defs,我只需对我的项目目录进行一些更改,考虑关于它们的适当消息,然后执行以下操作:
$fab committag
我在服务器上标记和更新了更改。或者:
$fab committag brpush
我创建了一个新分支并更新了服务器。