#!/usr/bin/env python
# vim: fileencoding=utf8 tw=120 expandtab ts=4 sw=4 :

# Ponytile
# A command-line tool to use the Ponytile library and generate CSS Sprites.
#
# Copyright (c) 2012 Rémy Sanchez <remy.sanchez@hyperthese.net>
# Under the terms of the WTFPL

from __future__ import print_function
from ponytile import Ponytile
import argparse

def fail(msg):
    import sys
    print("An error occured: %s" % msg, file=sys.stderr)
    sys.exit(1)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='A command-line tool to use the Ponytile library and generate CSS '
                                                 + 'sprites. It takes a .ptl file as input and generates both a '
                                                 + 'CSS file (from the command-line option) and a sprite image file '
                                                 + '(whose path is specified from the PTL file). The relative path '
                                                 + 'to the image file automatically calculated.', add_help=True)
    parser.add_argument('input', help='The PTL input file to read the configuration from. Source images paths are '
                                      + 'relative to this file')
    parser.add_argument('output', help='The CSS output file to generate. The generated sprite file\'s path is '
                                       + 'relative to the CSS file.')

    args = parser.parse_args()

    # All right, we should have everything needed now
    ptl = Ponytile(args.input)

    err = ptl.load_cfg()
    if err is not None:
        fail(err)

    err = ptl.compile(args.output)
    if err is not None:
        fail(err)
