#!/bin/bash -e


#
# Configuration
#
PYPI_NAME=PyICL
HOST=zemlinsky
DIR=www/PyICL
UPLOAD_URL="http://pypi.python.org/pypi?%3Aaction=pkg_edit&name=$PYPI_NAME"


#
# Check everything is checked in
#
if ! git st | grep "working directory clean"
then
  git st
  echo "*************************************************************"
  echo "You need to check in everything before updating distribution."
  echo "*************************************************************"
  exit -1
fi


#
# Update the documentation and upload to pypi and our web host
#
pip install sphinx sphinx-pypi-upload
LD_LIBRARY_PATH=/home/john/local/lib PYTHONPATH=Python python setup.py build_sphinx
LD_LIBRARY_PATH=/home/john/local/lib PYTHONPATH=Python python setup.py upload_sphinx
scp -r docs/build/html/* $HOST:$DIR/docs/build/html/


#
# Upload source build to pypi and our web host
#
python setup.py sdist upload --sign
PACKAGE=$(ls -rt dist|tail -1) # get the latest package in dist/
scp dist/$PACKAGE $HOST:$DIR/dist/


#
# Remind user
#
echo "**************************************************************************"
echo "* Now is a good time to update the release number in the python package. *"
echo "**************************************************************************"
