Commits

Anonymous committed 07ea743

Deal better with $PROJECT_ROOT having no Django projects; code cleanup; more messages to stderr

Comments (0)

Files changed (3)

bin/djenv.mercurial

 function hgkill() {
     kill -9 `cat "$hgpidfile" 2>&1` > /dev/null 2>&1
     if [ ! $? -eq 0 ]; then
-        echo Server not running or other error 2>&1
+        echo "Server not running or other error" 1>&2
     fi
 }
 
         eval `import_django_settings $dirs`
         envname=DJANGO_$dirs
         for dir in ${!envname}; do
-            [ ! -d $dir ] && echo "Warning: \"$dir\" in settings.$dirs is not a valid directory"
+            [ ! -d $dir ] && echo "Warning: \"$dir\" in settings.$dirs is not a valid directory" 1>&2
         done
     done
 
     fi
     djexit
     PROJECT_ROOT=`pwd`
-    echo "Available Django projects (use the djenv command to select):"
-    echo `show_django_projects`
+
+    local projects=`show_django_projects`
+    if [ ! -z "$projects" ]; then
+        echo "Available Django projects (use the djenv command to select):" 1>&2
+        echo $projects 1>&2
+    else
+        echo "Warning: no django projects found" 1>&2
+    fi
 }
 
 # Change directory to project root
 function show_django_projects() {
     _verify_project_root || return 1
 
-    (cd $PROJECT_ROOT; for f in */settings/__init__.py; do echo $f; done) | \
-        sed 's#/settings/__init__.py##' | sort
+    (
+        cd $PROJECT_ROOT
+        shopt -s nullglob
+        for file in */settings/__init__.py; do
+            echo $file
+        done
+    ) | sed 's#/settings/__init__.py##' | sort
 }
 
 function show_django_settings() {
     _verify_project_root || return 1
 
-    (cd $PROJECT_ROOT/$1; for f in settings/env/*.py; do echo $f; done) | \
-        grep -v '/__init__.py$' | sed 's#settings/env/#settings.env.#' | \
+    (
+        cd $PROJECT_ROOT/$1
+        shopt -s nullglob
+        for file in settings/env/*.py; do
+            echo $file
+        done
+    ) | grep -v '/__init__.py$' | sed 's#settings/env/#settings.env.#' | \
         sed 's#\.py$##' | sort
 }
 
 _cdroot_complete() {
     _verify_project_root || return 1
 
-    COMPREPLY=($(cdroot && compgen -d -- "${2}" ))
+    COMPREPLY=($(cdroot && compgen -d -- "${2}"))
 }
 
 _cdjango_complete() {
     _verify_django_project || return 1
 
-    COMPREPLY=($(cdjango && compgen -d -- "${2}" ))
+    COMPREPLY=($(cdjango && compgen -d -- "${2}"))
 }
 
 function show_pip_environments() {
     _verify_project_root || return 1
 
-    (cd $PROJECT_ROOT/requirements; for f in libs-*.txt; do echo $f; done) | \
-        sed 's#libs-##' | sed 's#.txt##' | sort
+    (
+        cd $PROJECT_ROOT/requirements
+        shopt -s nullglob
+        for file in libs-*.txt; do
+             echo $file
+        done
+    ) | sed 's#libs-##' | sed 's#.txt##' | sort
 }
 
 _pipup_complete() {

bin/run_in_env_wrapper.sh

 
 # Check for help request
 if [ "$1" = "-h" -o "$1" = "--help" ]; then
-    echo "Usage: `basename $0` <command> [args...]"
-    echo
-    echo "Where <command> is any of the following:"
+    echo "Usage: `basename $0` <command> [args...]" 1>&2
+    echo 1>&2
+    echo "Where <command> is any of the following:" 1>&2
     for file in $APP_HOME/*; do
-        [ -x $file -a `basename $file` != `basename $0` ] && echo "    "`basename $file`
+        [ -x $file -a `basename $file` != `basename $0` ] && echo "    "`basename $file` 1>&2
     done
     exit
 fi