#/bin/sh
# -*- mode: sh; tab-width: 8; encoding: utf-8-unix -*-

PREFIX=/usr/local
[ -f /usr/local/etc/testforge/testforge.bash ] && \
    . /usr/local/etc/testforge/testforge.bash
ROLE=toxcore

PYVER=3
P="BASE_PYTHON${PYVER}_MINOR"
[ -z "$PYTHON_MINOR" ] && PYTHON_MINOR="$(eval echo \$$P)"
PYTHON_EXE_MSYS=$PREFIX/bin/python$PYVER.bash
PYTHON_EXE=$PYTHON_EXE_MSYS
DESC=""
. /usr/local/src/usr_local_src.bash || exit 1
SITE_PACKAGES_MSYS=$PREFIX/$LIB/python$PYTHON_MINOR/site-packages
HTTP_DIR=$PREFIX/net/Http

DIR=tox_profile
MOD=$DIR
GIT_HUB=git.plastiras.org
GIT_USER=emdee
GIT_DIR=$DIR
# tox_profile

cd $PREFIX/src || exit 2
WD=$PWD

if [ "$#" -eq 0 ] ; then

    if [ !  -d "$DIR" ] ; then
	if [ ! -d "$PREFIX/net/Git/$GIT_HUB/$GIT_USER/$GIT_DIR" ] ; then
	    msys_are_we_connected || exit 0
	    [ -d "$PREFIX/net/Git/$GIT_HUB/$GIT_USER" ] || \
		mkdir "$PREFIX/net/Git/$GIT_HUB/$GIT_USER"
	    ( cd "$PREFIX/net/Git/$GIT_HUB/$GIT_USER" && \
		  git clone "https://$GIT_HUB/$GIT_USER/$GIT_DIR" ) ||\
		exit 2
	    ( cd "$PREFIX/net/Git/$GIT_HUB/$GIT_USER" && \
		  git config user emdee && \
		  git config email emdee@ )
	          
	fi
	cp -rip "$PREFIX/net/Git/$GIT_HUB/$GIT_USER/$GIT_DIR" . || exit 3
    fi
    
    python$PYVER.sh -c 'import namedlist' || \
	pip$PYVER.sh install namedlist
	
    cd $DIR || exit 4
    [ -f __init__.py ] || touch __init__.py

#    "$PYTHON_EXE_MSYS" -c "import $MOD" 2>/dev/null || exit 10

    exit 0

elif [ $1 = 'check' ] ; then # 1*
 #   "$PYTHON_EXE_MSYS" -c "import $MOD" 2>/dev/null || exit 10
    :
    
elif [ "$1" = 'lint' ] ; then # 2*
    [ -n "$PYVER" ] || return 20
    pylint -E --recursive y  ||  exit 2$?

elif [ "$1" = 'test' ] ; then # 3*

    cd $PREFIX/src/$DIR/$DIR || exit 32
    $PYTHON_EXE_MSYS tox_savefile_test.bash \
		     >> $WD/$DIR/test.log 2>&1 || \
	{ ERROR "$MOD code $?" ; cat $WD/$DIR/test.log  ; exit 35 ; }

elif [ "$1" = 'refresh' ] ; then # 6*
    cd $PREFIX/src/$DIR || exit 60

fi
