#!/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='''
{% if _mime_type == 'text/plain' %}

Host ........ {{ unspec(host) }}
Host Node ... {{ unspec(hostnode) }}
Interface ... {{ unspec(interface) }}
SSID ........ {{ unspec(ssid) }}
Duration .... {{ unspec(duration) }}
Timeout ..... {{ unspec(timeout) }}

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

<table>
<tr><td>Host</td><td>{{ unspec(host) }}</td></tr>
<tr><td>Host Node</td><td>{{ unspec(hostnode) }}</td></tr>
<tr><td>Interface</td><td>{{ unspec(interface) }}</td></tr>
<tr><td>SSID</td><td>{{ unspec(ssid) }}</td></tr>
<tr><td>Duration</td><td>{{ unspec(duration) }}</td></tr>
<tr><td>Timeout</td><td>{{ unspec(timeout) }}</td></tr>
</table>

{% else %}

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

{% endif %}
'''

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