#!/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.graphviz.image_converter import ImageConverter


def parse():
    """Parse CLI arguments"""
    parser = argparse.ArgumentParser(
        description='Convert GraphViz dot file to PNG image. '
            'The dot file has to be provided on stdin '
            'and the output s produced on stdout.')
    default_dot_program_path = '/usr/bin/dot'
    parser.add_argument('--dot_program', default=default_dot_program_path, 
        metavar='PATH',
        help='The path to the "dot" program from GraphViz library. '
            'The default value is "{}".'\
                .format(default_dot_program_path))
    args = parser.parse_args()
    return args

args = parse()
dot_string = sys.stdin.read()
dot_processor = ImageConverter(dot_string, dot_program_path=args.dot_program)
image = dot_processor.to_image()
sys.stdout.buffer.write(image)