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

set -e

# Presence of $ADTTMP implies that someone will handle cleanup for us
if [ -z "$ADTTMP" ]
then
	echo "Required envvar ADTTMP 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 $ADTTMP, and execute it
mkdir -p "$ADTTMP/$PYINTERPRETER"
cp examples/simple_train.py "$ADTTMP/$PYINTERPRETER"
cp examples/xor.data "$ADTTMP/$PYINTERPRETER"
cd "$ADTTMP/$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"
