Created
September 30, 2011 01:10
-
-
Save sjl/1252397 to your computer and use it in GitHub Desktop.
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
PASS_THROUGH = ('sudo password:', '[y/n]') | |
class CustomStringIO(StringIO): | |
def write(self, s, *args, **kwargs): | |
if any(pt in s.lower() for pt in PASS_THROUGH): | |
sys.__stdout__.write(s) | |
return super(CustomStringIO, self).write(s, *args, **kwargs) | |
_stored_out = CustomStringIO() | |
_out_log = open("fabric.log", 'w') | |
class Output(object): | |
def __init__(self, message=""): | |
self.message = message | |
def __enter__(self): | |
if self.message: | |
fastprint(colors.white(self.message.ljust(40) + " -> ", bold=True)) | |
sys.stdout = _out_log | |
sys.stderr = _out_log | |
if self.message: | |
fastprint("\n\n") | |
fastprint(colors.yellow("+" + "-" * 78 + "+\n", bold=True)) | |
fastprint(colors.yellow("| " + self.message.ljust(76) + " |\n", bold=True)) | |
fastprint(colors.yellow("+" + "-" * 78 + "+\n", bold=True)) | |
return self | |
def __exit__(self, type, value, tb): | |
sys.stdout = sys.__stdout__ | |
sys.stderr = sys.__stderr__ | |
fastprint(colors.green("OK\n", bold=True)) | |
def fastprint(self, s): | |
sys.stdout = sys.__stdout__ | |
fastprint(s) | |
sys.stdout = _out_log | |
def fastprintln(self, s): | |
self.fastprint(s + '\n') | |
def local(*args, **kwargs): | |
'''Override Fabric's local() to facilitate output logging.''' | |
capture = kwargs.get('capture') | |
kwargs['capture'] = True | |
out = _local(*args, **kwargs) | |
if capture: | |
return out | |
else: | |
print out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment