Created
August 29, 2011 18:37
-
-
Save gregglind/1179075 to your computer and use it in GitHub Desktop.
'ignore_abort' for twiedenbein
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
$ fab -f blah.py -H web03 somefun | |
[web03] Executing task 'somefun' | |
[web03] sudo: uname -a | |
Fatal error: Name lookup failed for web03 | |
Aborting. | |
would have aborted, but env.ignore_abort 1 | |
Done. | |
""" | |
import sys | |
import fabric | |
from fabric.api import task, env, get, put, hide, show, cd, lcd, local, run, sudo | |
from fabric.decorators import runs_once | |
from fabric.operations import get,open_shell,put,run,sudo,local | |
from fabric.contrib.console import confirm | |
from fabric.utils import abort | |
from functools import wraps | |
# env['ignore_abort'] = True # set using the unabort action | |
def ignore_abort(func): | |
""" | |
catch aborts, and just move on | |
""" | |
@wraps(func) | |
def decorated(*args, **kwargs): | |
if env.get('ignore_abort',False): | |
try: | |
return func(*args, **kwargs) | |
except SystemExit as exc: | |
print "would have aborted, but env.ignore_abort", exc | |
return None | |
else: | |
return func(*args, **kwargs) | |
return decorated | |
@task | |
@ignore_abort | |
def somefun(): | |
sudo('uname -a') | |
@task | |
@run_once | |
def unabort(): | |
"set env.ingore_abort" | |
env.ignore_abort = True | |
return None | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment