#!/bin/sh
# Consolidates common code of the autopkgtests
# Requires that AUTOPKGTEST_TMP and PYINTERPRETER are set

set -e

# Presence of $AUTOPKGTEST_TMP implies that someone will handle cleanup for us
if [ -z "$AUTOPKGTEST_TMP" ]
then
	echo "Required envvar AUTOPKGTEST is not set" >&2
	exit 1
fi

if [ -z "$PYINTERPRETER" ]
then
	echo "Python interpreter PYINTERPRETER is not set" >&2
	exit 1
fi

# Copy the simple example and the training data to $AUTOPKGTEST, and execute it
mkdir -p "$AUTOPKGTEST_TMP/$PYINTERPRETER"
cp examples/simple_train.py "$AUTOPKGTEST_TMP/$PYINTERPRETER"
cp examples/xor.data "$AUTOPKGTEST_TMP/$PYINTERPRETER"
cd "$AUTOPKGTEST_TMP/$PYINTERPRETER"

if [ "$1" = "pyfann" ]
then
	sed -i -r -e 's/from fann2/from pyfann/' simple_train.py
fi

$PYINTERPRETER simple_train.py
echo "run: OK"
