Making run_test.sh python version and directory
agnostic

Refactored some of the shell scripts to handle
being run from another directory, as well as to
not force the use of 2.6

edit: format the comments

Change-Id: Id92b9dc82743598b7c570e431cad423c8a2ee95d
diff --git a/kong/run_tests.sh b/kong/run_tests.sh
index 4010fcd..a7d7f63 100755
--- a/kong/run_tests.sh
+++ b/kong/run_tests.sh
@@ -33,8 +33,9 @@
   esac
 }
 
+base_dir=$(dirname $0)
 venv=.kong-venv
-with_venv=tools/with_venv.sh
+with_venv=../tools/with_venv.sh
 always_venv=0
 never_venv=0
 force=0
@@ -59,35 +60,38 @@
   ${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE || exit 1
 }
 NOSETESTS="env python run_tests.py $noseargs"
-
-if [ $never_venv -eq 0 ]
-then
-  # Remove the virtual environment if --force used
-  if [ $force -eq 1 ]; then
-    echo "Cleaning virtualenv..."
-    rm -rf ${venv}
-  fi
-  if [ -e ${venv} ]; then
-    wrapper="${with_venv}"
-  else
-    if [ $always_venv -eq 1 ]; then
-      # Automatically install the virtualenv
-      use_ve='y'
-    else
-      echo -e "No virtual environment found...create one? (Y/n) \c"
-      read use_ve
+function setup_venv {
+    if [ $never_venv -eq 0 ]
+    then
+        # Remove the virtual environment if --force used
+        if [ $force -eq 1 ]; then
+            echo "Cleaning virtualenv..."
+            rm -rf ${venv}
+        fi
+        if [ -e ${venv} ]; then
+            wrapper="${with_venv}"
+        else
+            if [ $always_venv -eq 1 ]; then
+                # Automatically install the virtualenv
+                use_ve='y'
+            else
+                echo -e "No virtual environment found...create one? (Y/n) \c"
+                read use_ve
+            fi
+            if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
+                # Install the virtualenv and run the test suite in it
+                env python ../tools/install_venv.py
+                wrapper=${with_venv}
+            fi
+        fi
     fi
-    if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
-        # Install the virtualenv and run the test suite in it
-        env python ../tools/install_venv.py
-        wrapper=${with_venv}
-    fi
-  fi
-fi
+}
 
 if [ $just_pep8 -eq 1 ]; then
     run_pep8
     exit
 fi
 
+cd $base_dir
+setup_venv
 run_tests || exit