#!/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 Port ..... {{ unspec(destport) }}
IP Version ........... {{ unspec(ipversion) }}
Packet Length ........ {{ unspec(length) }}
Probe Type ........... {{ unspec(probe-type) }}
Hops ................. {{ unspec(hops) }}
Queries .............. {{ unspec(queries) }}
First TTL ............ {{ unspec(firstttl) }}
Fragment ............. {{ unspec(fragment) }}
Resolve Hostnames .... {{ unspec(hostnames} }}
Algorithm ............ {{ unspec(algorithm) }}
Reslove ASes ......... {{ unspec(as) }}
IP Type of Service ... {{ unspec(iptos) }}
{%- if schema >= 2 %}
Flow Label ........... {{ unspec(flowlabel) }}
{%- endif -%}
Send Wait ............ {{ unspec(sendwait }}
Wait ................. {{ unspec(wait) }}

{% 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 Port</td><td>{{ unspec(destport) }}</td></tr>
<tr><td>IP Version</td><td>{{ unspec(ipversion) }}</td></tr>
<tr><td>Packet Length</td><td>{{ unspec(length) }}</td></tr>
<tr><td>Probe Type</td><td>{{ unspec(probe-type) }}</td></tr>
<tr><td>Hops</td><td>{{ unspec(hops) }}</td></tr>
<tr><td>Queries</td><td>{{ unspec(queries) }}</td></tr>
<tr><td>First TTL</td><td>{{ unspec(firstttl) }}</td></tr>
<tr><td>Fragment</td><td>{{ unspec(fragment) }}</td></tr>
<tr><td>Resolve Hostnames</td><td>{{ unspec(hostnames} }}</td></tr>
<tr><td>Algorithm</td><td>{{ unspec(algorithm) }}</td></tr>
<tr><td>Reslove ASes</td><td>{{ unspec(as) }}</td></tr>
<tr><td>IP Type of Service</td><td>{{ unspec(iptos) }}</td></tr>
{%- if schema >= 2 %}
<tr><td>Flow Label</td><td>{{ unspec(flowlabel) }}</td></tr>
{%- endif -%}
<tr><td>Send Wait</td><td>{{ unspec(sendwait }}</td></tr>
<tr><td>Wait</td><td>{{ unspec(wait) }}</td></tr>
</table>

{% else %}

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

{% endif %}
'''

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