#!/usr/bin/env python3
#
# Format a spec
#

import pscheduler

from validate import spec_is_valid
from validate import MAX_SCHEMA

TEMPLATE='''
{%- set schema = 1 if schema is undefined else schema -%}
{% if _mime_type == 'text/plain' %}

Source ................ {{ unspec(source) }}
Source Node ........... {{ unspec(sourcenode) }}
Destination ........... {{ unspec(dest) }}
Destination Node ...... {{ unspec(destnode) }}
{%- if schema >= 2 %}
IP Version ............ {{ unspec(ipversion) }}
{%- endif -%}
{%- if schema >= 3 %}
Port .................. {{ unspec(port) }}
{%- endif -%}
Test Material ......... {{ unspec(testmaterial) }}
Dawdle ................ {{ unspec(dawdle) }}
Timeout ............... {{ unspec(timeout) }}
Failure Probability ... {{ unspec(fail) }}

{% elif _mime_type == 'text/html' %}

<table>
<tr><td>Source</td><td>{{ unspec(source) }}</td></tr>
<tr><td>Source Node</td><td>{{ unspec(sourcenode) }}</td></tr>
<tr><td>Destination</td><td>{{ unspec(dest) }}</td></tr>
<tr><td>Destination Node</td><td>{{ unspec(destnode) }}</td></tr>
{%- if schema >= 2 %}
<tr><td>IP Version</td><td>{{ unspec(ipversion) }}</td></tr>
{%- endif -%}
{%- if schema >= 3 %}
<tr><td>Port</td><td>{{ unspec(port) }}</td></tr>
{%- endif -%}
<tr><td>Test Material</td><td>{{ unspec(testmaterial) }}</td></tr>
<tr><td>Dawdle</td><td>{{ unspec(dawdle) }}</td></tr>
<tr><td>Timeout</td><td>{{ unspec(timeout) }}</td></tr>
<tr><td>Failure Probability</td><td>{{ unspec(fail) }}</td></tr>
</table>

{% else %}

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

{% endif %}
'''

pscheduler.spec_format_method(TEMPLATE, max_schema=MAX_SCHEMA, validator=spec_is_valid)
