Skip to content

Commit

Permalink
Added a few scripts to assist devs
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed May 12, 2013
1 parent 7fe3522 commit 63dccaf
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
71 changes: 71 additions & 0 deletions scripts/mongo-db-ctl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#! /usr/bin/env bash

function usage()
{
echo "USAGE: $0 <start|stop|restart]>"
exit 1
}

if [ $# -ne 1 ]; then
usage
fi
ARG=$1

BASE=$(dirname $(dirname $0))
TEST_DBPATH=$BASE/testdb
LOGFILE=$TEST_DBPATH/victims.mongo.log
LOCKFILE="${TEST_DBPATH}/mongod.lock"

function start()
{
if [ ! -f "${LOCKFILE}" ]; then
if [ ! -d "${TEST_DBPATH}" ]; then
mkdir -p "${TEST_DBPATH}"
NEW="new"
fi
nohup mongod --logpath "${LOGFILE}" --dbpath "${TEST_DBPATH}" >> /dev/null 2>&1 &
echo "Waiting for mongodb to be ready..."
sleep 1
while true; do
match=$(grep -m 1 "waiting for connections on port" "${LOGFILE}")
if [ ! -z "$match" ]; then
if [ ! -z $NEW ]; then
mongoimport -d victims -c hashes "$BASE/test/mongo_test.json"
fi
break;
else
match=$(grep -m 1 "dbexit" "${LOGFILE}")
if [ ! -z "$match" ]; then
echo "ERROR starting database"
if [ ! -z $NEW ]; then
cat ${LOGFILE}
rm -rf ${TEST_DBPATH}
fi
break;
else
sleep 2
fi
fi
done
echo "Data: ${TEST_DBPATH}, Log: ${LOGFILE}"
else
echo "Datase already running"
fi
}

function stop()
{
mongod --shutdown --dbpath "${TEST_DBPATH}"
rm -f "${LOCKFILE}"
}

case "$ARG" in
"start" )
start ;;
"stop" )
stop ;;
"restart" )
stop; start ;;
* )
echo "Invalid argument."; usage ;;
esac
16 changes: 16 additions & 0 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /usr/bin/env bash
# to be run in the dev environment

SCRIPT_DIR=$(dirname $0)

MONGOSH="$SCRIPT_DIR/mongo-db-ctl.sh"
# gracefully start db
bash "$MONGOSH" start

# execute tests
BASE=$(dirname "$SCRIPT_DIR")
python /usr/bin/nosetests --with-coverage --cover-package=victims_web --cover-min-percentage=0 -v ${BASE}/test/*.py

# stop db
bash "$MONGOSH" stop

33 changes: 33 additions & 0 deletions scripts/start-dev-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Usage: source <script>
# Switch to dev environment
# Sets up the development environment if it does not exist

ENV_PREFIX=victims
ENV_PYTHON=python
ENV_DIR=${ENV_PREFIX}.dev
ENV_PROMPT=${ENV_PREFIX}.dev

# We know pip is installed, so use it
CMD="pip install"

function initialize {
$CMD "$(pwd)"
$CMD coverage nose pep8 --use-mirrors
$CMD -e . --use-mirrors
}

function vitualize {
if [ ! -d "$ENV_DIR" ]; then
virtualenv -p $(which ${ENV_PYTHON}) --prompt=${ENV_PROMPT} ${ENV_DIR}
source ${ENV_DIR}/bin/activate
initialize
else
source ${ENV_DIR}/bin/activate
fi

}


# We require virtuaenv and (easy_install/pip) to be installed
{ command -v virtualenv >/dev/null 2>&1 && vitualize; } || { echo >&2 "ERROR: virtualenv command not found, not switching"; }

0 comments on commit 63dccaf

Please sign in to comment.