Permalink
Browse files

Add script for initializing new django project

  • Loading branch information...
1 parent d0adc18 commit 35cecd58cbd4466b4811e143fda9a5ec51158905 @bkabrda committed Dec 20, 2012
Showing with 75 additions and 0 deletions.
  1. +75 −0 python27-django-new-app
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+HELP="Usage: $0 [-n NAME]
+ -n [--name] NAME create Django project named NAME (directory NAME must not
+ exist). Defaults to 'app'."
+
+export NAME=app
+
+ARGS=`getopt -q -o "n:" -l "name:" -- $*`
+
+if [ $? -ne 0 ]; then
+ echo "$HELP"
+ exit 1
+fi
+eval set -- "$ARGS"
+
+while true; do
+ case "$1" in
+ -n|--name)
+ NAME=$2
+ shift 2;;
+ --)
+ if [ -n "$2" ]; then
+ echo "Unexpected parameter '$2'."
+ echo "$HELP"
+ exit 1
+ fi
+ shift
+ break;;
+ esac
+done
+
+if [ -e $NAME ]; then
+ echo "Directory $NAME already exists, please choose a different path."
+ exit 2
+else
+ mkdir -p $NAME
+fi
+
+export ABS_PATH=`readlink -m $NAME`
+export ACTIVATE="$ABS_PATH/virtenv/bin/activate"
+export ACTIVATE_PY="${ACTIVATE}_this.py"
+
+scl enable python27 - << \EOF
+virtualenv --system-site-packages --prompt \(python27\) --distribute $NAME/virtenv
+pushd $NAME > /dev/null
+
+chmod +x virtenv/bin/activate
+source virtenv/bin/activate
+pip install Django
+django-admin.py startproject $NAME
+if [ $? -ne 0 ]; then
+ exit
+fi
+sed -i "s|import os|import os\n\
+activate_this = '$ACTIVATE_PY'\n\
+execfile(activate_this, dict(__file__ = activate_this)|" $NAME/$NAME/wsgi.py
+
+if [ $? -eq 0 ]; then
+ cat > develop << DEVELOP
+scl enable python27 bash
+DEVELOP
+ echo "
+Your Django project is ready in '$NAME/$NAME'.
+To get switched to the development environment, use
+
+cd $ABS_PATH
+source $ABS_PATH/develop
+source $ACTIVATE"
+else
+ echo 'There was an error creating new application.'
+fi
+
+popd > /dev/null
+EOF

0 comments on commit 35cecd5

Please sign in to comment.