#!/bin/sh

THIS_DIR=`dirname "$0"`
BASE_DIR="$THIS_DIR/.."

STORETYPE=file

if [ "$STORETYPE" = "file" ]; then
    STORE=/tmp/store
    JOURNAL=/tmp/journal
elif [ "$STORETYPE" = "postgresql" ]; then
    DBNAME='test'
    STORE="dbname=$DBNAME"
    JOURNAL="$STORE"
fi

STATIC=/tmp/static
PREFS=/tmp/prefs

ARGS="-T $STORETYPE -S $STORE -P $STATIC -p $PREFS -j $JOURNAL -d"

ACCEPT_SCRIPT="$THIS_DIR/test_handle.py"
ACCEPT_ARGS="accept $STORETYPE $STORE $JOURNAL $PREFS"

COUNTER_SCRIPT="$THIS_DIR/test_handle.py"
COUNTER_ARGS="counter $STORETYPE $STORE $JOURNAL $PREFS"

DECLINE_SCRIPT="$THIS_DIR/test_handle.py"
DECLINE_ARGS="decline $STORETYPE $STORE $JOURNAL $PREFS"

FREEBUSY_SCRIPT="$BASE_DIR/tools/make_freebusy.py"
FREEBUSY_ARGS="-s -n"

LIST_SCRIPT="$THIS_DIR/list_table.py"
LIST_ARGS="$STORETYPE $STORE $JOURNAL"

OUTGOING_SCRIPT="$BASE_DIR/imip_person_outgoing.py"

PERSON_SCRIPT="$BASE_DIR/imip_person.py"

RESOURCE_SCRIPT="$BASE_DIR/imip_resource.py"

SHOWMAIL="$BASE_DIR/tools/showmail.py"

TAB=`printf '\t'`

TEMPLATES="$THIS_DIR/templates"

ERROR=err.tmp

PYTHONPATH="$BASE_DIR"
export PYTHONPATH

if [ "$STORETYPE" = "file" ]; then
    rm -rf "$STORE"
    rm -rf "$JOURNAL"
elif [ "$STORETYPE" = "postgresql" ]; then
    dropdb "$DBNAME"
    createdb "$DBNAME"
    psql -f "$BASE_DIR/conf/postgresql/schema.sql" "$DBNAME"
fi

rm -rf "$STATIC"
rm -rf "$PREFS"
rm -f "$ERROR"
rm -f out*.tmp
