#!/bin/sh

# We need to execute checker.py rather than simply importing it.  However,
# since pychecker is not a private package, we don't know exactly where it will
# be located.  So, we run a little Python script first to find the correct
# location, and then execute it from there.
#
# Expect CHECKER_PATH to be something like:
#
#    /usr/share/pyshared/pychecker/checker.py
#
# Its actual location will depend on how dh_python2 is implemented.
#
# This script also supports the use of $PYTHONVER as a way to select which
# version of Python will be used to execute pychecker. This will only work for
# versions of Python supported by dh_python2, but it's better than nothing.

PYTHON="/usr/bin/python${PYTHONVER}"
CHECKER_PATH=`${PYTHON} -c "from imp import find_module; print find_module('pychecker/checker')[1]"`

if [ ! -n "${CHECKER_PATH}" ]; then
   echo "Unable to find checker.py on Python's module path."
   exit 1 
fi

if [ ! -f "${CHECKER_PATH}" ]; then
   echo "Found checker.py as [${CHECKER_PATH}], but it does not seem to exist."
   exit 1 
fi

exec "${PYTHON}" "${CHECKER_PATH}" "$@"

