Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the formatting of verdi calculation logshow #1850

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions aiida/cmdline/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def get_calculation_log_report(calculation):
calculation_state = calculation.get_state()
scheduler_state = calculation.get_scheduler_state()

report = []

if calculation_state == calc_states.WITHSCHEDULER:
state_string = '{}, scheduler state: {}'.format(calculation_state, scheduler_state
if scheduler_state else '(unknown)')
Expand All @@ -221,29 +223,30 @@ def get_calculation_log_report(calculation):

label_string = ' [{}]'.format(calculation.label) if calculation.label else ''

result = "*** {}{}: {}".format(calculation.pk, label_string, state_string)
report.append('*** {}{}: {}'.format(calculation.pk, label_string, state_string))

if scheduler_out is None:
result += '*** Scheduler output: N/A'
report.append('*** Scheduler output: N/A')
elif scheduler_out:
result += '*** Scheduler output:\n{}'.format(scheduler_out)
report.append('*** Scheduler output:\n{}'.format(scheduler_out))
else:
result += '*** (empty scheduler output file)'
report.append('*** (empty scheduler output file)')

if scheduler_err is None:
result += '*** Scheduler errors: N/A'
report.append('*** Scheduler errors: N/A')
elif scheduler_err:
result += '*** Scheduler errors:\n{}'.format(scheduler_err)
report.append('*** Scheduler errors:\n{}'.format(scheduler_err))
else:
result += '*** (empty scheduler errors file)'
report.append('*** (empty scheduler errors file)')

if log_messages:
result += '*** {} LOG MESSAGES:'.format(len(log_messages))
report.append('*** {} LOG MESSAGES:'.format(len(log_messages)))
else:
result += '*** 0 LOG MESSAGES'
report.append('*** 0 LOG MESSAGES')

for log in log_messages:
result += '+-> {} at {}'.format(log['levelname'], log['time'])
result += '\n'.join(['| {}'.format(message) for message in log['message'].splitlines()])
report.append('+-> {} at {}'.format(log['levelname'], log['time']))
for message in log['message'].splitlines():
report.append(' | {}'.format(message))

return result
return '\n'.join(report)