#!/usr/bin/env python3

#
# Development Order #9:
#
# This will format a test spec into something that is human readable.
#
# To test this file, a spec is needed. You can generate one with cli-to-spec
# after you've written it. Use the following syntax:
# cat example-spec.json | ./spec-format text/plain
# cat example-spec.json | ./spec-format text/html
# 
#

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) }}
Port .......... {{ unspec(port) }}
{% if schema >= 2 -%}
IP Version .... {{ unspec(ipversion) }}
{%- endif %}

{% 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>Port</td><td>{{ unspec(port) }}</td></tr>
{% if schema >= 2 -%}
<tr><td>IP Version</td><td>{{ unspec(ipversion) }}</td></tr>
{%- endif %}
</table>

{% else %}

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

{% endif %}
'''

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