Some code refactoring + output upgrades

pull/3/head
Michael DeHaan 13 years ago
parent 859c572de8
commit d6dcaefa9f

@ -80,30 +80,44 @@ def main(args):
results = runner.run() results = runner.run()
for hn in sorted(results['contacted']): for hostname in sorted(results['contacted']):
d = results['contacted'][hn]
if d.get('rc', 0) != 0 or d.get('failed', 0): result = results['contacted'][hostname]
msg = 'Error: %s: ' % hn rc = result.get('rc',0)
failed = result.get('failed', 0)
stdout = result.get('stdout', '')
stderr = result.get('stderr', '')
traceback = result.get('traceback', '')
error = result.get('error', '')
if rc != 0 or failed:
msg = 'Error: %s: ' % hostname
# too bad stdout/stderr is not interleaved :( # too bad stdout/stderr is not interleaved :(
msg += d.get('stdout', '') msg += stdout
msg += d.get('stderr', '') msg += stderr
msg += d.get('traceback', '') msg += traceback
msg += d.get('error', '') msg += error
error_print(msg) error_print(msg)
continue continue
if options.one_line: if options.one_line:
print '%s | rc=%s | %s:%s' % (hn, d['rc'], d['stdout'], d['stderr']) msg = "(stdout) %s" % stdout
if stderr.rstrip() != '':
msg = "(stdout) %s (stderr) %s" % (stdout,stderr)
print "%s | rc=%s | %s" % (
hostname, rc, msg
)
else: else:
print "%s: => rc=%s" % (hn, d['rc']) print "%s | rc=%s >>" % (hostname, rc)
print '%s' % d['stdout'] print stdout
if d.get('stderr', None): if stderr:
print '%s' % d['stderr'] print stderr
if results['dark']: if results['dark']:
error_print('Hosts which could not be contacted or did not respond:') error_print('Hosts which could not be contacted or did not respond:')
for hn in sorted(results['dark']): failed_hosts = results['dark'].keys()
error_print(hn) for hostname in keys:
error_print("%s:%s" % (hostname, results['dark'][hostname]))
print '' print ''

Loading…
Cancel
Save