Merge pull request #263 from dw/dmw
Stray mux process on CTRL+C, EINTR on async task timeout, temp dir cleanup racepull/274/head
commit
876a82f00d
@ -0,0 +1,54 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
import io
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.plugins import callback_loader
|
||||||
|
except ImportError:
|
||||||
|
from ansible.plugins.loader import callback_loader
|
||||||
|
|
||||||
|
|
||||||
|
def printi(tio, obj, key=None, indent=0):
|
||||||
|
def write(s, *args):
|
||||||
|
if args:
|
||||||
|
s %= args
|
||||||
|
tio.write(' ' * indent)
|
||||||
|
if key is not None:
|
||||||
|
tio.write('%s: ' % (key,))
|
||||||
|
tio.write(s)
|
||||||
|
tio.write('\n')
|
||||||
|
|
||||||
|
if isinstance(obj, (list, tuple)):
|
||||||
|
write('[')
|
||||||
|
for i, obj2 in enumerate(obj):
|
||||||
|
printi(tio, obj2, key=i, indent=indent+1)
|
||||||
|
key = None
|
||||||
|
write(']')
|
||||||
|
elif isinstance(obj, dict):
|
||||||
|
write('{')
|
||||||
|
for key2, obj2 in sorted(obj.iteritems()):
|
||||||
|
if not (key2.startswith('_ansible_') or
|
||||||
|
key2.endswith('_lines')):
|
||||||
|
printi(tio, obj2, key=key2, indent=indent+1)
|
||||||
|
key = None
|
||||||
|
write('}')
|
||||||
|
elif isinstance(obj, basestring):
|
||||||
|
if isinstance(obj, str):
|
||||||
|
obj = obj.decode('utf-8', 'replace')
|
||||||
|
for line in obj.splitlines():
|
||||||
|
write('%s', line.rstrip('\r\n'))
|
||||||
|
else:
|
||||||
|
write('%r', obj)
|
||||||
|
|
||||||
|
|
||||||
|
DefaultModule = callback_loader.get('default', class_only=True)
|
||||||
|
|
||||||
|
class CallbackModule(DefaultModule):
|
||||||
|
def _dump_results(self, result, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
tio = io.StringIO()
|
||||||
|
printi(tio, result)
|
||||||
|
return tio.getvalue().encode('ascii', 'replace')
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
raise
|
||||||
Loading…
Reference in New Issue