#!/usr/bin/python
"""Usage: kidc [OPTIONS] [file...]
Compile kid templates into Python byte-code (.pyc) files. 

OPTIONS:
  -f, --force                      Force compilation even if .pyc file already exists.
  -s, --source                     Generate .py source files along with .pyc files. This
                                   is sometimes useful for debugging.
  -d, --strip-dest-dir <destdir>   Strips the supplied path from the beginning of source
                                   filenames stored for error messages in the generated
                                   .pyc files

Files list may have files and/or directories. If a directory is specified,
all .kid files found in the directory and any sub-directories are compiled.
"""

__revision__ = "$Rev: 139 $"
__date__ = "$Date: 2005-03-14 19:28:22 -0500 (Mon, 14 Mar 2005) $"
__author__ = "Ryan Tomayko (rtomayko@gmail.com)"
__copyright__ = "Copyright 2004-2005, Ryan Tomayko"
__license__ = "MIT <http://www.opensource.org/licenses/mit-license.php>"

import sys
  
try:
  import kid
except ImportError:
  from os.path import join as joinpath, dirname, abspath
  import os
  # adjust sys.path if we're running directly within a source distribution
  bin_dir = dirname(__file__)
  lib_dir = abspath(joinpath(bin_dir, '..'))
  if os.access(joinpath(lib_dir, 'kid', '__init__.py'), os.F_OK):
    sys.path.insert(0, lib_dir)
  import kid

from kid.compiler import kidc, KidcUsageError
try:
  kidc(sys.argv)
except KidcUsageError, e:
  msg = str(e)
  if msg != 'help':
    print msg
  sys.stdout.write(__doc__)
except:
  if isinstance(sys.exc_type, str):
    sys.stderr.write(sys.exc_type + '\n')
  else:
    raise
