#!/usr/bin/env python
# Copyright 2012-2014 VPAC
#
# This file is part of pytsm.
#
# pytsm is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pytsm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pytsm.  If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
from __future__ import unicode_literals

import sys
import pytsm

if __name__ == "__main__":
    if len(sys.argv) <= 2:
        raise RuntimeError("Not enough parameters")

    d = pytsm.dsmadmc()
    d.auto_open(sys.argv[1])

    f = pytsm.get_formatter(output_format="readable")

    results = d.execute(" ".join(sys.argv[2::]))
    f.output_head(" ".join(sys.argv[2::]))
    f.output_results(results, [])
    d.close()
    f.output_tail()
