<commit_before>#!/bin/bash

PACKAGE_DEPENDENCIES=( ansible-playbook vagrant )
ANSIBLE_VERSION=1.9
DIRS=( keys certs logs tests )
_V=0
TAIL_LOGS=0

usage() {
  cat <<EOF
    Usage: $0 [options] environment
    -h    Display help message
    -v    Verbose mode
EOF
exit 1;
}

log () {
  if [[ $_V -eq 1 ]]; then
      echo "$@"
      echo ""
  fi
}

check_for_dependencies() {
  for d in "${PACKAGE_DEPENDENCIES[@]}";
  do
    command -v  $d >/dev/null 2>&1 || { echo >&2 "$d binary not found. Please make sure it is installed."; exit 1; }
  done
}

check_ansible_version() {
  ansible --version|head -1|awk '{ print $2 }'
}

launch_auth() {
  log "Bringing VM machine up"
  vagrant up --no-provision
  log "Bringing VM machine up"
  vagrant rsync-auto &
  log "Starting provisioning of Authority Server"
  vagrant provision
}

create_dirs() {
  log "Creating directories ${DIRS[@]}"
  mkdir -p "${DIRS[@]}"
}

clean_up() {
  for dir in "${DIRS[@]}";
  do
    rm -rf $dir/*
  done
}

clean_up_db() {
  vagrant ssh -c 'sudo -u eorchestra psql -c "delete from authority ; delete from session; delete from election;delete from message; delete from query_queue;  delete from task;"'
}

tail_logs() {
  log "Tailing logs from Authority Server"
  while true;
  do
    tail -f logs/*.log
    sleep 3
  done
}

while getopts "hvtr" opt; do
  case $opt in
    h)
      usage
      exit 0
      ;;
    v)
      _V=1
      ;;
    t)
      TAIL_LOGS=1
      ;;
    r)
      clean_up
      clean_up_db
      ;;
  esac
done


check_for_dependencies
launch_auth

[[ $TAIL_LOGS -eq 1 ]] && tail_logs
<commit_msg>Add logging to -r action<commit_after>#!/bin/bash

PACKAGE_DEPENDENCIES=( ansible-playbook vagrant )
ANSIBLE_VERSION=1.9
DIRS=( keys certs logs tests )
_V=0
TAIL_LOGS=0

usage() {
  cat <<EOF
    Usage: $0 [options] environment
    -h    Display help message
    -v    Verbose mode
EOF
exit 1;
}

log () {
  if [[ $_V -eq 1 ]]; then
      echo "$@"
      echo ""
  fi
}

check_for_dependencies() {
  for d in "${PACKAGE_DEPENDENCIES[@]}";
  do
    command -v  $d >/dev/null 2>&1 || { echo >&2 "$d binary not found. Please make sure it is installed."; exit 1; }
  done
}

check_ansible_version() {
  ansible --version|head -1|awk '{ print $2 }'
}

launch_auth() {
  log "Bringing VM machine up"
  vagrant up --no-provision
  log "Bringing VM machine up"
  vagrant rsync-auto &
  log "Starting provisioning of Authority Server"
  vagrant provision
}

create_dirs() {
  log "Creating directories ${DIRS[@]}"
  mkdir -p "${DIRS[@]}"
}

clean_up() {
  log "Removing temporary directories"
  for dir in "${DIRS[@]}";
  do
    rm -rf $dir/*
  done
}

clean_up_db() {
  log "Cleaning up database"
  vagrant ssh -c 'sudo -u eorchestra psql -c "delete from authority ; delete from session; delete from election;delete from message; delete from query_queue;  delete from task;"'
}

tail_logs() {
  log "Tailing logs from Authority Server"
  while true;
  do
    tail -f logs/*.log
    sleep 3
  done
}

while getopts "hvtr" opt; do
  case $opt in
    h)
      usage
      exit 0
      ;;
    v)
      _V=1
      ;;
    t)
      TAIL_LOGS=1
      ;;
    r)
      log "Cleaning up"
      clean_up
      clean_up_db
      ;;
  esac
done


check_for_dependencies
launch_auth

[[ $TAIL_LOGS -eq 1 ]] && tail_logs

{'fraction_non_alphanumeric': 0.12488605287146765, 'fraction_numerical': 0.010938924339106655, 'mean_word_length': 2.653718091009989, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1814603', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1227, 'n_words': 377}