<commit_before>#!/bin/bash
#
#   reset.sh: INSTALL OR RESET APPIUM
#   This script should ensure that after pulling the most recent code,
#   you will be in a state where you can run tests and use appium
#
set -e
should_reset_android=false
should_reset_ios=false
should_reset_selendroid=false
should_reset_gappium=false
should_reset_firefoxos=false
should_reset_realsafari=false
code_sign_identity='';
provisioning_profile='';
include_dev=false
prod_deps=false
appium_home=$(pwd)
reset_successful=false
has_reset_unlock_apk=false
apidemos_reset=false
hardcore=false
grunt="$(npm bin)/grunt"  # might not have grunt-cli installed with -g
verbose=false

while test $# != 0
do
    case "$1" in
        "--android") should_reset_android=true;;
        "--ios") should_reset_ios=true;;
        "--real-safari") should_reset_realsafari=true;;
        "--code-sign") code_sign_identity=$2;;
        "--profile") provisioning_profile=$2;;
        "--selendroid") should_reset_selendroid=true;;
        "--firefoxos") should_reset_firefoxos=true;;
        "--gappium") should_reset_gappium=true;;
        "--dev") include_dev=true;;
        "--prod") prod_deps=true;;
        "-v") verbose=true;;
        "--verbose") verbose=true;;
        "--hardcore") hardcore=true;;
    esac
    if [[ -n "$2" ]] && [[ "$2" != --* ]]; then
      shift
      shift
    else
      shift
    fi
done

if ! $should_reset_android && ! $should_reset_ios && ! $should_reset_selendroid && ! $should_reset_gappium && ! $should_reset_firefoxos ; then
    should_reset_android=true
    should_reset_ios=true
    should_reset_selendroid=true
    should_reset_gappium=true
    should_reset_firefoxos=true
fi

if ! $should_reset_ios && $should_reset_realsafari; then
    should_reset_ios=true
fi

run_cmd() {
    if $verbose ; then
        "$@"
    else
        "$@" >/dev/null 2>&1
    fi
}

reset_general() {
    echo "RESETTING NPM"
    set +e
    if $hardcore ; then
        echo "* Removing NPM modules"
        run_cmd rm -rf node_modules
        echo "* Clearing out old .appiumconfig"
        run_cmd rm -rf ./.appiumconfig
    fi
    if $prod_deps ; then
        echo "* Installing new or updated NPM modules"
        run_cmd npm install --production .
    else
        echo "* Installing new or updated NPM modules (including devDeps)"
        run_cmd npm install .
    fi
    install_status=$?
    set -e
    if [ $install_status -gt 0 ]; then
        echo "install failed. Trying again with sudo. Only do this if it's not a network error."
        run_cmd sudo npm install .
    fi
    if $hardcore ; then
        echo "* Clearing out build dir"
        run_cmd rm -rf build
    fi
    run_cmd mkdir -p build
    echo "* Setting git revision data"
    run_cmd $grunt setGitRev
}

reset_ios() {
    echo "RESETTING IOS"
    echo "* Cloning/updating ForceQuitUnresponsiveApps"
    run_cmd git submodule update --init submodules/ForceQuitUnresponsiveApps
    echo "* Building ForceQuitUnresponsiveApps"
    run_cmd pushd submodules/ForceQuitUnresponsiveApps
    run_cmd ./build_force_quit.sh
    run_cmd popd
    echo "* Moving ForceQuitUnresponsiveApps into build/force_quit"
    run_cmd rm -rf build/force_quit
    run_cmd mkdir build/force_quit
    run_cmd cp -R submodules/ForceQuitUnresponsiveApps/bin/* build/force_quit
    echo "* Cloning/updating instruments-without-delay"
    run_cmd git submodule update --init submodules/instruments-without-delay
    echo "* Building instruments-without-delay"
    run_cmd pushd submodules/instruments-without-delay
    run_cmd ./build.sh<commit_msg>show a warning in reset.sh if you're not on ios7<commit_after>#!/bin/bash
#
#   reset.sh: INSTALL OR RESET APPIUM
#   This script should ensure that after pulling the most recent code,
#   you will be in a state where you can run tests and use appium
#
set -e
should_reset_android=false
should_reset_ios=false
should_reset_selendroid=false
should_reset_gappium=false
should_reset_firefoxos=false
should_reset_realsafari=false
code_sign_identity='';
provisioning_profile='';
include_dev=false
prod_deps=false
appium_home=$(pwd)
reset_successful=false
has_reset_unlock_apk=false
apidemos_reset=false
hardcore=false
grunt="$(npm bin)/grunt"  # might not have grunt-cli installed with -g
verbose=false

while test $# != 0
do
    case "$1" in
        "--android") should_reset_android=true;;
        "--ios") should_reset_ios=true;;
        "--real-safari") should_reset_realsafari=true;;
        "--code-sign") code_sign_identity=$2;;
        "--profile") provisioning_profile=$2;;
        "--selendroid") should_reset_selendroid=true;;
        "--firefoxos") should_reset_firefoxos=true;;
        "--gappium") should_reset_gappium=true;;
        "--dev") include_dev=true;;
        "--prod") prod_deps=true;;
        "-v") verbose=true;;
        "--verbose") verbose=true;;
        "--hardcore") hardcore=true;;
    esac
    if [[ -n "$2" ]] && [[ "$2" != --* ]]; then
      shift
      shift
    else
      shift
    fi
done

if ! $should_reset_android && ! $should_reset_ios && ! $should_reset_selendroid && ! $should_reset_gappium && ! $should_reset_firefoxos ; then
    should_reset_android=true
    should_reset_ios=true
    should_reset_selendroid=true
    should_reset_gappium=true
    should_reset_firefoxos=true
fi

if ! $should_reset_ios && $should_reset_realsafari; then
    should_reset_ios=true
fi

run_cmd() {
    if $verbose ; then
        "$@"
    else
        "$@" >/dev/null 2>&1
    fi
}

reset_general() {
    echo "RESETTING NPM"
    set +e
    if $hardcore ; then
        echo "* Removing NPM modules"
        run_cmd rm -rf node_modules
        echo "* Clearing out old .appiumconfig"
        run_cmd rm -rf ./.appiumconfig
    fi
    if $prod_deps ; then
        echo "* Installing new or updated NPM modules"
        run_cmd npm install --production .
    else
        echo "* Installing new or updated NPM modules (including devDeps)"
        run_cmd npm install .
    fi
    install_status=$?
    set -e
    if [ $install_status -gt 0 ]; then
        echo "install failed. Trying again with sudo. Only do this if it's not a network error."
        run_cmd sudo npm install .
    fi
    if $hardcore ; then
        echo "* Clearing out build dir"
        run_cmd rm -rf build
    fi
    run_cmd mkdir -p build
    echo "* Setting git revision data"
    run_cmd $grunt setGitRev
}

reset_ios() {
    echo "RESETTING IOS"
    set +e
    sdk_ver=$(xcrun --sdk iphonesimulator --show-sdk-version 2>/dev/null)
    sdk_status=$?
    set -e
    if [ $sdk_status -gt 0 ] || [[ "$sdk_ver" != "7."* ]]; then
      echo "--------------------------------------------------"
      echo "WARNING: you do not appear to have iOS7 SDK active"
      echo "--------------------------------------------------"
    fi
    echo "* Cloning/updating ForceQuitUnresponsiveApps"
    run_cmd git submodule update --init submodules/ForceQuitUnresponsiveApps
    echo "* Building ForceQuitUnresponsiveApps"
    run_cmd pushd submodules/ForceQuitUnresponsiveApps
    run_cmd ./build_force_quit.sh
    run_cmd popd
    echo "* Moving ForceQuitUnresponsiveApps into build/force_quit"
    run_cmd rm -rf build/force_quit
    run_cmd mkdir build/force_quit
    run_cmd cp -R submodules/ForceQuitUnresponsiveApps/bin/* build/force_quit
    echo "* Cloning/updating instruments-without-delay"
    run_cmd git submodule update --init submodules/instruments-without-delay
    echo "* Building instruments-without-delay"
    run_cmd pushd submodules/instruments-without-delay
    run_cmd ./build.sh
{'fraction_non_alphanumeric': 0.11321504237288135, 'fraction_numerical': 0.0030455508474576272, 'mean_word_length': 2.887287699433865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '578826', 'n_tokens_mistral': 2470, 'n_tokens_neox': 2403, 'n_words': 631}