<commit_before>#!/usr/bin/env bash
set -e

while getopts 'u:g:' OPT; do
  case $OPT in
    u)
      URL=$OPTARG
      ;;
    g)
      COORD=$OPTARG
      ;;
  esac
done

if [ -z $URL ] || [ -z $COORD ]; then
  echo "USAGE: $0 -u URL -g hg19" >&2
  exit 1
fi

set -o verbose

# TODO: Do we have a story yet where the user should care about this?
export USERNAME=username
export PASSWORD=password
/home/higlass/projects/create_user.sh
CREDENTIALS=$USERNAME:$PASSWORD

PORT=8888
python /home/higlass/projects/higlass-server/manage.py runserver localhost:$PORT &
DJANGO_PID=$!

TILESETS_URL=http://localhost:$PORT/api/v1/tilesets/

set +e # So we don't exit travis, instead of exiting the loop.
TRY=0;
until $(curl --output /dev/null --silent --fail --globoff $TILESETS_URL) || [[ $TRY -gt 20 ]]; do
    echo "try $TRY"
    (( TRY++ ))
    sleep 1
done
set -e

DOWNLOADS=/tmp/downloads
mkdir -p $DOWNLOADS
NAME=`basename $URL`
wget -O $DOWNLOADS/$NAME $URL

if [[ "$NAME" == *.cool ]]; then
    CMD="curl -F datafile=@$DOWNLOADS/$NAME -u $CREDENTIALS
              -F filetype=cooler -F datatype=matrix
              -F coordSystem=$COORD
              $TILESETS_URL"
elif [[ "$NAME" == *.hitile ]]; then
    CMD="curl -F datafile=@$DOWNLOADS/$NAME -u $CREDENTIALS
              -F filetype=hitile -F datatype=vector
              -F coordSystem=$COORD
              $TILESETS_URL"
else
    # TODO: Add other formats?
    echo "Unrecognized file type: $NAME" >&2
    exit 1
fi

echo $CMD
$CMD

kill $DJANGO_PID
<commit_msg>This seems to clean up django, even with ctrl-c (#110)<commit_after>#!/usr/bin/env bash
set -e

trap 'pkill -P $$' EXIT # Kill the Django subprocess.

while getopts 'u:g:' OPT; do
  case $OPT in
    u)
      URL=$OPTARG
      ;;
    g)
      COORD=$OPTARG
      ;;
  esac
done

if [ -z $URL ] || [ -z $COORD ]; then
  echo "USAGE: $0 -u URL -g hg19" >&2
  exit 1
fi

set -o verbose

# TODO: Do we have a story yet where the user should care about this?
export USERNAME=username
export PASSWORD=password
/home/higlass/projects/create_user.sh
CREDENTIALS=$USERNAME:$PASSWORD

PORT=8888
python /home/higlass/projects/higlass-server/manage.py runserver localhost:$PORT &

TILESETS_URL=http://localhost:$PORT/api/v1/tilesets/

set +e # So we don't exit travis, instead of exiting the loop.
TRY=0;
until $(curl --output /dev/null --silent --fail --globoff $TILESETS_URL) || [[ $TRY -gt 20 ]]; do
    echo "try $TRY"
    (( TRY++ ))
    sleep 1
done
set -e

DOWNLOADS=/tmp/downloads
mkdir -p $DOWNLOADS
NAME=`basename $URL`
wget -O $DOWNLOADS/$NAME $URL

if [[ "$NAME" == *.cool ]]; then
    CMD="curl -F datafile=@$DOWNLOADS/$NAME -u $CREDENTIALS
              -F filetype=cooler -F datatype=matrix
              -F coordSystem=$COORD
              $TILESETS_URL"
elif [[ "$NAME" == *.hitile ]]; then
    CMD="curl -F datafile=@$DOWNLOADS/$NAME -u $CREDENTIALS
              -F filetype=hitile -F datatype=vector
              -F coordSystem=$COORD
              $TILESETS_URL"
else
    # TODO: Add other formats?
    echo "Unrecognized file type: $NAME" >&2
    exit 1
fi

echo $CMD
$CMD

{'fraction_non_alphanumeric': 0.13862024500322373, 'fraction_numerical': 0.011283043197936816, 'mean_word_length': 2.7117224880382773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2844201', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1136, 'n_words': 334}