<commit_before>#    Copyright 2016 Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

cleanup_server() {
    echo "Stopping Nailgun and waiting $NAILGUN_START_MAX_WAIT_TIME seconds."
    local pid="$(lsof -ti tcp:${NAILGUN_PORT})"
    local kill9=0
    if [[ -z "$pid" ]]; then
        return 0
    fi
    kill ${pid} >/dev/null 2>&1
    for i in $(seq 1 $NAILGUN_START_MAX_WAIT_TIME); do
        if kill -0 ${pid} >/dev/null 2>&1; then
            kill9=1
            sleep 1
        else
            kill9=0
            break
        fi
    done
    if  [[ ${kill9} -ne 0  ]]; then
        kill -9 ${pid} >/dev/null 2>&1
    fi
    return 0
}

cleanup_nailgun_env() {
    rm -f "$NAILGUN_LOGS/nailgun.log"
    rm -f "$NAILGUN_LOGS/app.log"
    rm -f "$NAILGUN_LOGS/api.log"
    rm -f "${NAILGUN_CONFIG}"
}

prepare_nailgun_env() {
    mkdir -p $(dirname "${NAILGUN_CONFIG}")
    mkdir -p $(dirname "${NAILGUN_LOGS}")
    cat > "${NAILGUN_CONFIG}" <<EOL
DEVELOPMENT: 1
STATIC_DIR: "${NAILGUN_STATIC}"
TEMPLATE_DIR: "${NAILGUN_TEMPLATES}"
DATABASE:
  name: "${NAILGUN_DB}"
  engine: "postgresql"
  host: "${NAILGUN_DB_HOST}"
  port: "${NAILGUN_DB_PORT}"
  user: "${NAILGUN_DB_USER}"
  passwd: "${<PASSWORD>GUN_DB_USERPW}"
API_LOG: "${NAILGUN_LOGS}/api.log"
APP_LOG: "${NAILGUN_LOGS}/app.log"
APP_LOGLEVEL: "ERROR"
RPC_CONSUMER_LOG_PATH: "${NAILGUN_LOGS}/receiverd.log"
ASSASSIN_LOG_PATH: "${NAILGUN_LOGS}/assassind.log"
STATS_LOGS_PATH: ${NAILGUN_LOGS}
LCM_SERIALIZERS_CONCURRENCY_FACTOR: 1
EOL
}

prepare_server() {
    python ${NAILGUN_ROOT}/manage.py dropdb > /dev/null
    python ${NAILGUN_ROOT}/manage.py syncdb > /dev/null
    python ${NAILGUN_ROOT}/manage.py loaddefault > /dev/null
    if test -n "$NAILGUN_FIXTURE_FILES"; then
        for nailgun_fixture_file in $NAILGUN_FIXTURE_FILES; do
            python ${NAILGUN_ROOT}/manage.py loaddata $nailgun_fixture_file > /dev/null
        done
    fi

    python ${NAILGUN_ROOT}/manage.py run \
        --port=$NAILGUN_PORT \
        --config="$NAILGUN_CONFIG" \
        --fake-tasks \
        --fake-tasks-tick-count=80 \
        --fake-tasks-tick-interval=1 >> "$NAILGUN_LOGS/nailgun.log" 2>&1 &

    which curl >/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
        echo "WARNING: Cannot check whether Nailgun is running bacause curl is not available."
        return 1<commit_msg>The typo in the warning needs to be fixed.<commit_after>#    Copyright 2016 Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

cleanup_server() {
    echo "Stopping Nailgun and waiting $NAILGUN_START_MAX_WAIT_TIME seconds."
    local pid="$(lsof -ti tcp:${NAILGUN_PORT})"
    local kill9=0
    if [[ -z "$pid" ]]; then
        return 0
    fi
    kill ${pid} >/dev/null 2>&1
    for i in $(seq 1 $NAILGUN_START_MAX_WAIT_TIME); do
        if kill -0 ${pid} >/dev/null 2>&1; then
            kill9=1
            sleep 1
        else
            kill9=0
            break
        fi
    done
    if  [[ ${kill9} -ne 0  ]]; then
        kill -9 ${pid} >/dev/null 2>&1
    fi
    return 0
}

cleanup_nailgun_env() {
    rm -f "$NAILGUN_LOGS/nailgun.log"
    rm -f "$NAILGUN_LOGS/app.log"
    rm -f "$NAILGUN_LOGS/api.log"
    rm -f "${NAILGUN_CONFIG}"
}

prepare_nailgun_env() {
    mkdir -p $(dirname "${NAILGUN_CONFIG}")
    mkdir -p $(dirname "${NAILGUN_LOGS}")
    cat > "${NAILGUN_CONFIG}" <<EOL
DEVELOPMENT: 1
STATIC_DIR: "${NAILGUN_STATIC}"
TEMPLATE_DIR: "${NAILGUN_TEMPLATES}"
DATABASE:
  name: "${NAILGUN_DB}"
  engine: "postgresql"
  host: "${NAILGUN_DB_HOST}"
  port: "${NAILGUN_DB_PORT}"
  user: "${NAILGUN_DB_USER}"
  passwd: "${<PASSWORD>}"
API_LOG: "${NAILGUN_LOGS}/api.log"
APP_LOG: "${NAILGUN_LOGS}/app.log"
APP_LOGLEVEL: "ERROR"
RPC_CONSUMER_LOG_PATH: "${NAILGUN_LOGS}/receiverd.log"
ASSASSIN_LOG_PATH: "${NAILGUN_LOGS}/assassind.log"
STATS_LOGS_PATH: ${NAILGUN_LOGS}
LCM_SERIALIZERS_CONCURRENCY_FACTOR: 1
EOL
}

prepare_server() {
    python ${NAILGUN_ROOT}/manage.py dropdb > /dev/null
    python ${NAILGUN_ROOT}/manage.py syncdb > /dev/null
    python ${NAILGUN_ROOT}/manage.py loaddefault > /dev/null
    if test -n "$NAILGUN_FIXTURE_FILES"; then
        for nailgun_fixture_file in $NAILGUN_FIXTURE_FILES; do
            python ${NAILGUN_ROOT}/manage.py loaddata $nailgun_fixture_file > /dev/null
        done
    fi

    python ${NAILGUN_ROOT}/manage.py run \
        --port=$NAILGUN_PORT \
        --config="$NAILGUN_CONFIG" \
        --fake-tasks \
        --fake-tasks-tick-count=80 \
        --fake-tasks-tick-interval=1 >> "$NAILGUN_LOGS/nailgun.log" 2>&1 &

    which curl >/dev/null 2>&1
    if [[ $? -ne 0 ]]; then
        echo "WARNING: Cannot check whether Nailgun is running because curl is not available."
        return 1
{'fraction_non_alphanumeric': 0.12708044382801664, 'fraction_numerical': 0.013522884882108182, 'mean_word_length': 2.9513698630136984, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1530813', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2103, 'n_words': 539}