#!/usr/bin/sh

home_dir=${PWD}

# Call common script
. createCommonStructure_test

python_prog_name="PythonProgramTest"

# Create a unique directory
tmploc=${TEMPORARY_LOCATION}

cd ${MODULE_NAME_PATH}

# Create python program
AddPythonProgram $python_prog_name --yes

# Error? stop and clean up
if [ $? -ne 0 ]; then
   echo "Error: <AddPythonProgram $python_prog_name> command failed!" 1>&2
   clean_and_exit 1
fi

# Make sure python files have been created
if [ ! -e python/${MODULE_NAME}/${python_prog_name}.py ]; then
   echo "Error: <python/${MODULE_NAME}/${python_prog_name}.py> file not found!" 1>&2
   clean_and_exit 1
fi

if [ ! -e python/${MODULE_NAME}/__init__.py ]; then
   echo "Error: <python/${MODULE_NAME}/__init__.py> file not found!" 1>&2
   clean_and_exit 1
fi

# Make sure the <elements_install_python_modules> macro is there
result=$( grep "elements_install_python_modules" CMakeLists.txt | grep -v "#")
if [ $? -ne 0  ];then
   echo "Error: <elements_install_python_modules> macro not found!" 1>&2
   clean_and_exit 1
fi

# Make sure the <elements_add_python_program> macro is there
result=$( grep "elements_add_python_program" CMakeLists.txt | grep -v "#" | grep ${python_prog_name})
if [ $? -ne 0  ];then
   echo "Error: <elements_add_python_program> macro and <${python_prog_name}> program not found!" 1>&2
   clean_and_exit 1
fi

clean_and_exit 0
