<commit_before>#!/bin/bash

readonly SCRIPT_PATH=$(dirname $0)
readonly SCRIPT_ABSOLUTE_PATH=$(cd $SCRIPT_PATH && pwd)

readonly RED=$(tput setaf 1)

readonly VER_EQ=0
readonly VER_GT=1
readonly VER_LT=2

function banner() {
  cat <<EOF
  __  __  ____ ____
 |  \/  |/ ___|  _ \
 | |\/| | |   | |_) |
 | |  | | |___|  __/
 |_|  |_|\____|_|

EOF
}

oc_version_comparison=${VER_LT}

# Returns:
# 0 - =
# 1 - >
# 2 - <
function compare_version () {
  if [[ $1 == $2 ]]; then
    return 0
  fi
  local IFS=.
  local i ver1=(${1}) ver2=(${2})
  for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
    ver1[i]=0
  done
  for ((i=0; i<${#ver1[@]}; i++)); do
    if [[ -z ${ver2[i]} ]]; then
      ver2[i]=0
    fi
    if ((10#${ver1[i]} > 10#${ver2[i]})); then
      return 1
    fi
    if ((10#${ver1[i]} < 10#${ver2[i]})); then
      return 2
    fi
  done
  return 0
}

function does_not_exist_msg() {
  echo -e "${RED}${1} does not exist on host machine."
  echo -e "It can be installed using ${2}."
}

function check_exists_msg() {
  echo -e "\nChecking ${1} exists"
}

function check_version_msg() {
  echo "Checking ${1} version. Should be ${2}"
}

function check_passed_msg() {
  echo "✓ ${1} check passed."
}

function check_docker() {
  docker_version=$(docker version --format '{{json .Client.Version}}')
  if [[ $docker_version == *"-rc"* ]]; then
    echo "Docker version is not good. Use latest Stable release"
    exit 1
  fi
}

function check_python() {
  check_exists_msg "Python"

  command -v python &>/dev/null
  python_exists=${?}; if [[ ${python_exists} -ne 0 ]]; then
    does_not_exist_msg "Python" "pip install ansible>=2.3"
  fi
  check_passed_msg "Python"

  readonly python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')

  check_version_msg "Python" ">= 2.7"
  compare_version ${python_version} 2.7
  python_version_comparison=${?}; if [[ ${python_version_comparison} -eq ${VER_LT} ]]; then
    echo -e "${RED}Python is < 2.7. Update to >= 2.7."
    exit 1
  fi
  check_passed_msg "Python"
}

function check_ansible() {
  check_exists_msg "Ansible"

  command -v ansible &>/dev/null
  ansible_exists=${?}; if [[ ${ansible_exists} -ne 0 ]]; then
    does_not_exist_msg "Ansible" "pip install ansible>=2.3"
    exit 1
  fi<commit_msg>Add logging to Docker check<commit_after>#!/bin/bash

readonly SCRIPT_PATH=$(dirname $0)
readonly SCRIPT_ABSOLUTE_PATH=$(cd $SCRIPT_PATH && pwd)

readonly RED=$(tput setaf 1)

readonly VER_EQ=0
readonly VER_GT=1
readonly VER_LT=2

function banner() {
  cat <<EOF
  __  __  ____ ____
 |  \/  |/ ___|  _ \
 | |\/| | |   | |_) |
 | |  | | |___|  __/
 |_|  |_|\____|_|

EOF
}

oc_version_comparison=${VER_LT}

# Returns:
# 0 - =
# 1 - >
# 2 - <
function compare_version () {
  if [[ $1 == $2 ]]; then
    return 0
  fi
  local IFS=.
  local i ver1=(${1}) ver2=(${2})
  for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
    ver1[i]=0
  done
  for ((i=0; i<${#ver1[@]}; i++)); do
    if [[ -z ${ver2[i]} ]]; then
      ver2[i]=0
    fi
    if ((10#${ver1[i]} > 10#${ver2[i]})); then
      return 1
    fi
    if ((10#${ver1[i]} < 10#${ver2[i]})); then
      return 2
    fi
  done
  return 0
}

function does_not_exist_msg() {
  echo -e "${RED}${1} does not exist on host machine."
  echo -e "It can be installed using ${2}."
}

function check_exists_msg() {
  echo -e "\nChecking ${1} exists"
}

function check_version_msg() {
  echo "Checking ${1} version. Should be ${2}"
}

function check_passed_msg() {
  echo "✓ ${1} check passed."
}

function check_docker() {
  check_version_msg "Docker" "using Stable channel"
  docker_version=$(docker version --format '{{json .Client.Version}}')
  if [[ $docker_version == *"-rc"* ]]; then
    echo "${RED}Docker version is not good. Use latest Stable release"
    exit 1
  fi
  check_passed_msg "Docker"
}

function check_python() {
  check_exists_msg "Python"

  command -v python &>/dev/null
  python_exists=${?}; if [[ ${python_exists} -ne 0 ]]; then
    does_not_exist_msg "Python" "pip install ansible>=2.3"
  fi
  check_passed_msg "Python"

  readonly python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')

  check_version_msg "Python" ">= 2.7"
  compare_version ${python_version} 2.7
  python_version_comparison=${?}; if [[ ${python_version_comparison} -eq ${VER_LT} ]]; then
    echo -e "${RED}Python is < 2.7. Update to >= 2.7."
    exit 1
  fi
  check_passed_msg "Python"
}

function check_ansible() {
  check_exists_msg "Ansible"

  command -v ansible &>/dev/null
  ansible_exists=${?}; if [[ ${ansible_exists} -ne 0 ]]; then
    does_not_exist_msg "Ansible" "pip install ansible>=2.3"
    exit 1
  fi
{'fraction_non_alphanumeric': 0.18452636090870125, 'fraction_numerical': 0.02700385769395628, 'mean_word_length': 3.4111531190926274, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '4782781', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1802, 'n_words': 450}