[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fab-user] fabric.expect
From: |
Jasper van den Bosch |
Subject: |
[Fab-user] fabric.expect |
Date: |
Wed, 4 Jan 2012 00:30:46 +0200 |
Dear fabric developers and users,
I have enjoyed working with fabric so far. However, wanting to automate a distribution upgrade I ran into the problem of prompts that I wish to deal with in an automated fashion, in line with issue 177 (
https://github.com/fabric/fabric/issues/177) Perhaps like this:
prompts = []
prompts += expect('*** release-upgrades','Y')
prompts += expect('*** sudoers','N')
prompts += expect('Do you want to continue?*Continue [yN]','y')
prompts += expect('the process cannot be cancelled.*Continue [yN]','y')
prompts += expect('packages are going to be removed.*Continue [yN]','y')
prompts += expect("the system will be restarted. *Continue [yN]",'N')
with expecting(prompts)
with prefix('export DEBIAN_FRONTEND=noninteractive'):
sudo('do-release-upgrade')
The expectations could be simple tuples, and the 'expecting' context manager save these to the fabric state, i.e. env:
from fabric.state import env
def expect(promptexpr, response):
return (promptexpr, response)
def expecting(e)
return ExpectationContext(e)
class ExpectationContext(object):
def __init__(self,expectations):
self.expectations = expectations
def __enter__(self):
env.expectations = self.expectations
def __exit__(self, type, value, tb):
env.expectations = []
Now I looked into the fabric source, but it seems someone who is more familiar and skilled than me could better find where to handle the expected prompts, however, line 145 in io.py seems a good candidate:
else:
if is_expected(capture): # compares capture with expectations
answer = answer_for(capture)
chan.sendall(answer + '\n') #sends respective response back
This is probably to simply thought. Also I have no experience with Git, which is my excuse for not sending this as a 'pull request'. What do you think?
Jasper van den Bosch
PS
this blogger solves this issue with pexpect and fabric combined.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fab-user] fabric.expect,
Jasper van den Bosch <=