#!/usr/bin/env python3

#
# Development Order #8:
#
# This file is called when perfSonar goes to print the result, which
# has been returned from the tool.
#
# To test this file, a result is needed. A sample one has been provided
# in this directory. Use the following syntax:
# cat example-result.json | ./result-format text/plain
# cat example-result.json | ./result-format text/html
#

import pscheduler

from validate import result_is_valid
from validate import MAX_SCHEMA

TEMPLATE = '''
{% if _mime_type == 'text/plain' %}

Authenticated ... {{ result.authenticated }}
Time ............ {{ result.time }}

{% elif _mime_type == 'text/html' %}
<table>
  <tr><td>Authenticated</td><td>{{ result.authenticated }}</td></tr>
  <tr><td>Time</td><td>{{ result.time }}</td></tr>
</table>

{% else %}

{{ error('Unsupported MIME type "' + _mime_type + '"') }}

{% endif %}
'''

pscheduler.result_format_method(TEMPLATE, max_schema=MAX_SCHEMA, validator=result_is_valid)
