13

这与此处的这个问题有关,但略有不同:我需要 Fabric 将任意字符串传递给远程 shell,而不是只传递“是”或“否”。

例如,如果远程 shell 提示“你叫什么名字?” 然后我需要先喂它,最后喂它。

澄清:我知道我说的是任意输入,但是当我尝试执行 git pull 时,我真的想将它用于 SSH 密钥 passwd 提示

更新 #1:得到 Jeff Forcier @bitprophet 的回复

4

5 回答 5

5

我已经在邮件列表中为 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')

请参阅我的博文,了解使用 fexpect 期待织物中的提示

于 2012-03-08T08:48:02.603 回答
4

Fabric 1.0 最终支持与远程服务器的交互。有关详细信息,请参阅此页面

于 2010-09-29T13:12:03.083 回答
2

也许看看pexpect

于 2010-04-16T04:50:26.103 回答
1

我已经建立了一个名为 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

我创建了一个新分支并更新了服务器。

于 2010-07-13T22:13:09.130 回答
1

跳过主机验证提示的一种方法是:

run('ssh-keyscan github.com > ~/.ssh/known_hosts')

另外,我正在使用py-github安装部署密钥:

run('ssh-keygen -q -t rsa -f /home/%(user)s/.ssh/id_rsa -N ""' % env)
key = run('cat /home/%(user)s/.ssh/id_rsa.pub' % env)
gh.repos.addDeployKey(repo, env.host, key)
于 2010-12-27T11:52:18.013 回答