Python结构:如何处理任意远程shell输入提示?
这与此相关,但有一点扭曲:我需要Fabric将任意字符串传递到远程shell,而不是仅仅传递“yes”或“no” 例如,如果远程shell提示输入“你叫什么名字?”那么我需要输入“first,last” 澄清:我知道我说的是任意输入,但我真的是 更新#1:从Jeff Forcier@bitprophet得到了回应Python结构:如何处理任意远程shell输入提示?,python,django,unix,shell,fabric,Python,Django,Unix,Shell,Fabric,这与此相关,但有一点扭曲:我需要Fabric将任意字符串传递到远程shell,而不是仅仅传递“yes”或“no” 例如,如果远程shell提示输入“你叫什么名字?”那么我需要输入“first,last” 澄清:我知道我说的是任意输入,但我真的是 更新#1:从Jeff Forcier@bitprophet得到了回应 也许可以研究一下我已经建立了一个名为project_name/.git的git源存储库 ssh to the server, (entering ssh password
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上的branchmaster中。Stll不使用fabric,只是进行设置,虽然我认为这些步骤也可以自动化,并且它们都不需要另一个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"
现在我开始使用织物。下面摘自我管理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 def,我只需对project dir进行一些更改,
想一个关于他们的恰当的信息,然后做:
$fab committag
我在服务器上标记并更新了更改。或:
$fab committag brpush
我创建了一个新分支并更新了服务器。Fabric 1.0最终支持与远程服务器的交互。有关详细信息,请参阅。跳过主机验证提示的一种方法是:
run('ssh-keyscan github.com > ~/.ssh/known_hosts')
另外,我正在使用安装
我在邮件列表中为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')
请看我在Hmm上的博客帖子,非常有趣,看起来它可以工作。我要试一试。谢谢你的提示!:)博客帖子链接不再有效,“ilogue.com正在出售”。。。这个博客在别处有吗?还是我们应该满足于归档页面?可能重复的
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')