#!/usr/bin/python3

# Copyright 2013-2016 University of Warsaw
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__author__ = "Mateusz Kobos mkobos@icm.edu.pl"

import sys
import argparse
from vipe.oozie.graph import OozieGraph
from vipe.oozie.converter.converter import convert
from vipe.oozie.converter.iis import IISPipelineConverter

def parse():
    """Parse CLI arguments"""
    parser = argparse.ArgumentParser(
        description='Convert YAML representation of a Oozie XML file to a '
            'pipeline representation. '
            'In this representation, workflow nodes have ports and these ' 
            'are connected to show the producer-consumer dependencies. '
            'It is assumed that the workflow representation follows '
            'conventions from the OpenAIRE IIS project. '
            'The YAML reprsentation of An Oozie XML file has to be provided '
            'on stdin and the output in YAML format is produced on stdout.')
    args = parser.parse_args()
    return args

args = parse()
oozie_yaml = sys.stdin.read()
oozie_graph = OozieGraph.from_yaml_dump(oozie_yaml)
pipeline = convert(oozie_graph, IISPipelineConverter())
pipeline_dump = pipeline.to_yaml_dump()
print(pipeline_dump)