Commits

Anonymous committed f796318 Merge

[merge]

Comments (0)

Files changed (19)

bin/create_apache_vhost_conf.sh

 domains=local
 [ ! -z "$DOMAIN" ] && domains=$DOMAIN
 
-# The root of the project should exist, of course
-[ -z "$PROJECT_ROOT" ] && \
-    echo "Variable \$PROJECT_ROOT not set or empty" 1>&2 && exit 1
-[ ! -d "$PROJECT_ROOT" ] && \
-     echo "Variable \$PROJECT_ROOT does not point to a readable directory" 1>&2 && exit 1
+[ `type -t djenv`'' != 'function' ] && echo "django-environments not loaded" 1>&2 && exit 1
+_verify_project_root || exit 1
 
 PROJECT=`basename $PROJECT_ROOT`
 
-cd `dirname $0`
 
 function write_vhost() {
-    echo '<VirtualHost *:*>'
+    local host_prefix=$1
+    local settings=$2
+    local port=`get_django_setting LOCAL_SERVER_PORT 8000 $settings`
+    local static_root=`get_django_setting STATIC_ROOT static $settings`
+    local static_id=`get_django_setting STATIC_ID static $settings`
+    local media_root=`get_django_setting MEDIA_ROOT media $settings`
+    local media_id=`get_django_setting MEDIA_ID static $settings`
+
+    echo "<VirtualHost *:*>"
 
     local directive=ServerName # First domain is the server name
     for domain in $domains; do
-        echo "    $directive $1.$2.$domain"
+        echo "    $directive $host_prefix.$PROJECT.$domain"
         directive=ServerAlias # The other domains are aliases
     done
 
     cat << EOF
     RewriteEngine On
     RewriteRule ^/favicon.ico [F]
-    RewriteRule ^/$4/(.*) $5/\$1 [L]
-    RewriteRule ^/$6/(.*) $7/\$1 [L]
-    RewriteRule ^/(.*) http://127.0.0.1:$3/\$1 [P]
+    RewriteRule ^/$static_id/(.*) $static_root/\$1 [L]
+    RewriteRule ^/$media_id/(.*) $media_root/\$1 [L]
+    RewriteRule ^/(.*) http://127.0.0.1:$port/\$1 [P]
 </VirtualHost>
 
 EOF
          -d "$django_project_dir/settings" ]; then
         export DJANGO_PROJECT=`basename $django_project_dir`
 
-        echo "#" $PROJECT $DJANGO_PROJECT \($django_project_dir\)
+        echo "# $PROJECT $DJANGO_PROJECT ($django_project_dir)"
 
-        port=`get_django_setting LOCAL_SERVER_PORT 8000 $DJANGO_PROJECT.settings`
-        static_root=`get_django_setting STATIC_ROOT static $DJANGO_PROJECT.settings`
-        static_id=`get_django_setting STATIC_ID static $DJANGO_PROJECT.settings`
-        media_root=`get_django_setting MEDIA_ROOT media $DJANGO_PROJECT.settings`
-        media_id=`get_django_setting MEDIA_ID static $DJANGO_PROJECT.settings`
-        write_vhost $DJANGO_PROJECT $PROJECT $port $static_id $static_root $media_id $media_root
+        write_vhost $DJANGO_PROJECT $DJANGO_PROJECT.settings
 
         # Per-environment settings
         for settings in $django_project_dir/settings/env/*.py; do
                              sed "s#[^/]*/settings/env/#settings.env.#" | sed 's#.py$##'`
             django_settings_id=`echo $django_settings | sed "s#.*\\.##"`
 
-            echo "#" $PROJECT $DJANGO_PROJECT $django_settings_id \($django_project_dir\)
-            port=`get_django_setting LOCAL_SERVER_PORT 8000 $DJANGO_PROJECT.$django_settings`
-            static_root=`get_django_setting STATIC_ROOT static $DJANGO_PROJECT.settings`
-            static_id=`get_django_setting STATIC_ID static $DJANGO_PROJECT.settings`
-            media_root=`get_django_setting MEDIA_ROOT media $DJANGO_PROJECT.settings`
-            media_id=`get_django_setting MEDIA_ID static $DJANGO_PROJECT.settings`
-            write_vhost $django_settings_id.$DJANGO_PROJECT $PROJECT $port $static_id $static_root $media_id $media_root
+            echo "# $PROJECT $DJANGO_PROJECT $django_settings_id ($django_project_dir)"
+            write_vhost $django_settings_id.$DJANGO_PROJECT $DJANGO_PROJECT.$django_settings
         done
 
     fi
 done
 
-echo '# <<<' Generated django-environments virtual host config end
+echo "# <<< Generated django-environments virtual host config end"
 #
 # django-environments initialization script
 #
-# Instead of editing the file, it's better to set the variable
-# $PROJECT_ROOT in your own initenv script or virtualenv bin/postactivate,
-# and then source this file.
+# Source this file, then use the "djp" command, or use "setproject"
+# and "djenv" manually.
 #
-# $PROJECT_ROOT is the path to the root of the *entire* project, i.e.
-# the directory containing one or more 'Django projects', for example:
-#
-# PROJECT_ROOT=/Users/spanky/projects/myproject
+
+DJENV_HOME=$(cd -P "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)
+DEFAULT_ROOT=/deploy
+DEFAULT_REPOS=$DEFAULT_ROOT/repos
 
 # Not to be called directly, see djenv below
 function _djenv_init() {
 
     # Show environment info
     if [ "$SHOW_DJANGO_ENVIRONMENT" = "yes" ]; then
-        echo Welcome to $DJANGO_PROJECT. Environment info:
+        echo "Welcome to `basename $PROJECT_ROOT`/$DJANGO_PROJECT. Environment info:"
         djenv
     fi
 
 # Example:
 # djenv # Print current environment settings
 # or
-# djenv mysite # Use default settings
+# djenv www # Use default settings
 # or
-# djenv mysite settings.env.local # Use specific settins
+# djenv www settings.env.local # Use specific settins
 function djenv() {
     # Environment info
     if [ -z "$1" ]; then
-        echo PROJECT_ROOT: \'$PROJECT_ROOT\'
-        echo DJANGO_PROJECT: \'$DJANGO_PROJECT\'
-        echo DJANGO_SETTINGS_MODULE: \'$DJANGO_SETTINGS_MODULE\'
-        echo PYTHONPATH: \'$PYTHONPATH\'
+        echo "PROJECT_ROOT: '$PROJECT_ROOT'"
+        echo "DJANGO_PROJECT: '$DJANGO_PROJECT'"
+        echo "DJANGO_SETTINGS_MODULE: '$DJANGO_SETTINGS_MODULE'"
+        echo "PYTHONPATH: '$PYTHONPATH'"
         return
     fi
 
     # Help
     if [ "$1" = "-h" -o "$1" = "--help" ]; then
-        echo "Usage: djenv [DJANGO_PROJECT [DJANGO_SETTINGS]]"
+        echo "Usage: djenv [Django project [Django settings]]"
         return
     fi
 
     fi
 
     DJANGO_SETTINGS_MODULE=$settings_module python << EOF
-try:
-    from django.conf import settings
-except ImportError:
-    print '$2'
-    raise
-else:
-    try:
-        print getattr(settings, '`echo $1 | tr 'a-z' 'A-Z'`', '')
-    except KeyError:
-        print '$2'
+from django.conf import settings
+print getattr(settings, '`echo $1 | tr 'a-z' 'A-Z'`', '$2')
 EOF
 }
 
 # Import django settings into the shell environment
-# Experimental.
 #
 # When using, set $IFS to empty (this is needed because we eval
 # the output of the python-generated shell script code):
 # to newline to get to those:
 # IFS='
 # '
-# Note that all variables are prefixed with value of $prefix, 'DJANGO_'.
+# Note that all variables are prefixed with 'DJANGO_'.
 function import_django_settings() {
     _verify_project_root || return 1
     _verify_django_settings_module || return 1
 
     prefix=DJANGO_
     python << EOF
-import $DJANGO_SETTINGS_MODULE as settings
+from django.conf import settings
 from types import TupleType, ListType, DictType
 
 def escape(value):
     return str(value).replace('"', '\\\\"')
 
-settings = settings.__dict__.items()
-settings.sort()
-for name, value in settings:
-    if name.find('__') == -1 and name.find('$1') == 0:
+prefix = '$1'.upper()
+for name in sorted(dir(settings)):
+    if name.isupper() and name.find('__') == -1 and name.find(prefix) == 0:
+        value = getattr(settings, name)
         if type(value) in (TupleType, ListType):
             print '$prefix%s="' % name
             for item in value:
             destination=`basename $source`
         fi
         if [ -L "$destination" ]; then
-            echo Not updating symbolic link $destination
+            echo "Not updating symbolic link $destination"
             return
         fi
         if [ ! -d $destination ]; then
         sed 's/$/c/' | xargs $extra_xargs_args rm -v" | bash
 }
 
-# Remove all directories in the project that contain the specified file
+# Remove all directories in the project that contain only the specified file.
 # Experimental.
 function cleanupdirs() {
     [ -z "$1" ] && echo "Usage: cleanupdirs <filename>" 1>&2 && return 1
     # Make directories as empty as possible
     removeorphanpycs
     cleanupdirs .DS_Store
-    # Then remove the totally empty ones
-    find $PROJECT_ROOT -type d -empty -delete
+    # Then remove the totally empty ones, depth first
+    find $PROJECT_ROOT -depth -type d -empty -delete
 }
 
 # Change directory to Django project
 
 # Forget manage.py, django-admin.py respects our settings!
 function djadmin() {
-    _verify_project_root || return 1
-
     django-admin.py $*
 }
 
     local port=`get_django_setting LOCAL_SERVER_PORT 8000`
 
     while true; do
-        django-admin.py runserver $ip$port $*
+        djadmin runserver $ip$port $*
         echo "Server exited - restarting" 1>&2
-        sleep 1
+        sleep 0.5
     done
 }
 
     _verify_project_root_and_django_project || return 1
 
     local port=`get_django_setting LOCAL_SERVER_PORT 8000`
-    django-admin.py testserver --addrport=$port $*
+    djadmin testserver --addrport=$port $*
 }
 
 # Open an URL in the default browser
     open_url http://$django_settings_id.$DJANGO_PROJECT.$PROJECT.$domain/$1
 }
 
+# Clear the cache via the Django cache API
+function clearcache() {
+    python << EOF
+from django.core.cache import cache
+from django.db.transaction import commit_on_success
+
+commit_on_success(cache.clear)()
+EOF
+}
+
+# Gracefully restart Apache if configuration test is succesful
+function graceful() {
+    sudo apachectl configtest && \
+    sudo apachectl -k graceful && \
+    echo "Apache restarted" 2>&1
+}
+
+# Make any Sphinx documentation. Provided arguments are passed to
+# the make command, default is "dirhtml".
+function makedocs() {
+    if [ -d "$PROJECT_ROOT/doc" ]; then
+        for makefile in `ls $PROJECT_ROOT/doc/*/Makefile`; do
+            dir=`dirname $makefile`
+            echo "Making docs in $dir..."
+            if [ "$1" ]; then
+                args=$*
+            else
+                args=dirhtml
+            fi
+            make --directory $dir $args
+            if [ $? -ne 0 ]; then
+                return 1
+            fi
+        done
+    fi
+}
+
+# Returns all Django projects that have a locale directory.
+function localized_django_projects() {
+    _verify_project_root || return 1
+
+    cdroot
+    for directory in `find * -type d -name locale`; do
+        directory=`dirname $directory`
+        if [ -f $directory/models.py -o -f $directory/models/__init__.py ];
+        then
+            echo $directory
+        fi
+    done
+}
+
+# Deploy the current Django application (and most of the project).
+function deploy() {
+    _verify_project_root_and_django_project || return 1
+    _verify_django_settings_module || return 1
+
+    echo ">>> Updating virtualenv..." 2>&1 && pipup prd > /dev/null && \
+        if [ -f "$PROJECT_ROOT/requirements/externals-prd.txt" ]; then
+            echo ">>> Updating externals..." 2>&1 && externalsup prd
+        else
+            echo ">>> No production externals defined" 2>&1
+        fi && \
+        echo 2>&1 && echo ">>> Compiling Python code..." 2>&1 && pycompile > /dev/null && \
+        echo ">>> Removing orphan .pyc files..." 2>&1 && removeorphanpycs > /dev/null && \
+        echo ">>> Validating models..." 2>&1 && djadmin validate && \
+        echo 2>&1 && echo ">>> Compiling messages..." 2>&1 && \
+            for dir in `localized_django_projects`; do
+                (cdroot $dir && djadmin compilemessages)
+            done && \
+        echo 2>&1 && echo ">>> Making documentation..." 2>&1 && makedocs && \
+        echo 2>&1 && echo ">>> Collecting static files..." 2>&1 && \
+            djadmin collectstatic --link --noinput && \
+        echo 2>&1 && echo ">>> Setting permissions..." 2>&1 && set_permissions.sh && \
+        echo 2>&1 && echo ">>> Clearing cache..." 2>&1 && clearcache && \
+        echo ">>> Restarting server..." 2>&1 && graceful && \
+        echo 2>&1 && echo "Ok." 2>&1 && \
+        return 0
+
+    echo 2>&1 && echo "Errors encountered - deploy aborted." 2>&1
+}
+
+# XXX
+function bootstrapproject() {
+    _verify_project_root || return 1
+
+    # Standard directories
+    for dir in bin db doc externals lib log media requirements static tmp; do
+        if [ ! -e $PROJECT_ROOT/$dir ]; then
+            mkdir $PROJECT_ROOT/$dir
+        fi
+    done
+
+    # Symlink to django-environments/etc
+    [ ! -L $PROJECT_ROOT/etc ] && \
+        ln -s externals/django-environments/etc $PROJECT_ROOT
+
+    # Django is a basic requirement
+    local libs=$PROJECT_ROOT/requirements/libs-prd.txt
+    [ ! -e $libs ] && echo "Django" > $libs
+    pipup prd || return 1
+
+    # Get django-environments as an external
+    local externals=$PROJECT_ROOT/requirements/externals-prd.txt
+    [ ! -e $externals ] && echo $DJENV_HOME > $externals
+    externalsup prd || return 1
+}
+
+# XXX
+function bootstrapdjangoproject() {
+    [ -z "$1" ] && \
+        echo "Usage: bootstrapdjangoproject <Django project>" 1>&2 && return 1
+    _verify_project_root || return 1
+
+    local path=$PROJECT_ROOT
+    for dir in $1 settings env; do
+        path=$path/$dir
+        if [ ! -d $path ]; then
+            mkdir $path
+            touch $path/__init__.py
+        fi
+    done
+    echo "from .generic import *" > \
+        $PROJECT_ROOT/$1/settings/__init__.py
+    echo "from etc.settings import *" > \
+        $PROJECT_ROOT/$1/settings/generic.py
+    echo "from .. import *" > \
+        $PROJECT_ROOT/$1/settings/env/local.py
+}
+
+# Start working on a project (first argument, optional second
+# argument is the Django project, default "www"), automatically
+# activating the virtualenv with the name of the project and selecting
+# "settings.env.local". Virtualenv and empty project are created if
+# they do not yet exist.
+function djp() {
+    [ -z "$1" ] && \
+        echo "Usage: djp <project> [Django project]" 1>&2 && return 1
+
+    # Exit possible environment
+    djexit
+
+    # Virtualenv
+    [ -z "$PIP_VIRTUALENV_BASE" ] && PIP_VIRTUALENV_BASE=$DEFAULT_ROOT/virtualenvs
+    if [ ! -d $PIP_VIRTUALENV_BASE/$1 ]; then
+        echo "Creating virtualenv $1 in $PIP_VIRTUALENV_BASE" 1>&2
+        virtualenv $PIP_VIRTUALENV_BASE/$1
+        if [ $? -ne 0 ]; then
+            echo "Error creating virtualenv $1" 1>&2
+            return 1
+        fi
+    fi
+    source $PIP_VIRTUALENV_BASE/$1/bin/activate
+    if [ $? -ne 0 ]; then
+        echo "Error activating virtualenv $1" 1>&2
+        return 1
+    fi
+
+    # Project
+    [ -z "$REPOS" ] && REPOS=$DEFAULT_REPOS
+    if [ ! -d $REPOS/$1 ]; then
+        mkdir $REPOS/$1
+        local project_created=true
+    fi
+    setproject $REPOS/$1 > /dev/null 2>&1
+    if [ $? -ne 0 ]; then
+        echo "Error changing project to $1" 1>&2
+        return 1
+    fi
+    if [ $project_created ]; then
+        bootstrapproject
+        if [ $? -ne 0 ]; then
+            echo "Error bootstrapping project" 1>&2
+            return 1
+        fi
+    fi
+
+    # Django project
+    local django_project=$2
+    [ -z "$django_project" ] && django_project=www
+    if [ ! -e $PROJECT_ROOT/$django_project/settings/env/local.py ]; then
+        bootstrapdjangoproject $django_project
+    fi
+    djenv $django_project settings.env.local
+    if [ $? -ne 0 ]; then
+        echo "Error setting Django project to $django_project" 1>&2
+        return 1
+    fi
+
+    # Shell search path (virtualenv manages PATH for us)
+    for bindir in $PROJECT_ROOT/*/*/bin $PROJECT_ROOT/*/bin $PROJECT_ROOT/bin; do
+        if [ -d $bindir ]; then
+            PATH=$bindir:$PATH
+        fi
+    done
+}
+
 # Clean up the environment
 function _djenv_cleanup () {
     unset DJANGO_PROJECT DJANGO_SETTINGS \
 # Use _djenv_register_cleanup to register your own cleanup functions
 _djenv_register_cleanup _djenv_cleanup
 
+function show_projects() {
+    (
+        [ -z "$REPOS" ] && REPOS=$DEFAULT_REPOS
+        cd $REPOS
+        shopt -s nullglob
+        find * -maxdepth 0 -type d
+    )
+}
+
 function show_django_projects() {
-    _verify_project_root || return 1
+    [ ! -z "$1" ] || _verify_project_root || return 1
 
     (
+        [ ! -z "$1" ] && PROJECT_ROOT=$REPOS/$1
         cd $PROJECT_ROOT
         shopt -s nullglob
         for file in */settings/__init__.py; do
     djexit djenv get_django_setting import_django_settings cdroot cdlib \
     pipup _externals externalsup pycompile removeorphanpycs cleanupdirs removeemptydirs \
     cdjango djadmin get_network_ip runserver testserver open_url djbrowse djvirtualbrowse \
-    _djenv_cleanup show_django_projects show_django_settings
+    clearcache graceful localized_django_projects makedocs deploy \
+    _djenv_cleanup show_projects show_django_projects show_django_settings
 
 #
 # Tab completion
 #
 
+_projects_complete() {
+    local current="${COMP_WORDS[COMP_CWORD]}"
+    local previous="${COMP_WORDS[COMP_CWORD - 1]}"
+
+    if [ $COMP_CWORD -eq 1 ]; then
+        COMPREPLY=($(compgen -W "`show_projects`" -- ${current}))
+    elif [ $COMP_CWORD -eq 2 ]; then
+        COMPREPLY=( $(compgen -W "`show_django_projects $previous`" -- ${current}) )
+    fi
+}
+
 _django_projects_complete() {
     local current="${COMP_WORDS[COMP_CWORD]}"
     local previous="${COMP_WORDS[COMP_CWORD - 1]}"
 complete -o nospace -F _cdroot_complete -S/ cdroot
 complete -o nospace -F _cdlib_complete -S/ cdlib
 complete -o nospace -F _cdjango_complete -S/ cdjango
+complete -F _projects_complete djp
 complete -F _django_projects_complete djenv
 complete -F _pipup_complete pipup
 complete -F _externalsup_complete externalsup

bin/run_in_env_wrapper.sh

 # - DJANGO_SETTINGS
 # - VIRTUAL_ENV (optional)
 
+[ `type -t djenv`'' != 'function' ] && echo "django-environments not loaded" 1>&2 && exit 1
+_verify_project_root_and_django_project || exit 1
+_verify_django_settings_module || exit 1
+
 APP_HOME=$(cd `dirname $0`; pwd) # Make sure we can refer back to this location
 
 # Update PATH

bin/set_permissions.sh

+#!/usr/bin/env bash
+
+[ `type -t djenv`'' != 'function' ] && echo "django-environments not loaded" 1>&2 && exit 1
+_verify_project_root || exit 1
+
+set -e
+
+directories=''
+for directory in `localized_django_projects`; do
+    directories="$directories $directory/locale/*/LC_MESSAGES"
+done
+directories="$directories db log media/generated media/medialibrary static/z */deploy"
+
+cd $PROJECT_ROOT
+
+user=$HTTP_USER
+[ -z "$user" ] && user=www-data
+group=$HTTP_GROUP
+[ -z "$group" ] && group=`groups | awk '{ print $1 }'`
+
+dirs=$*
+if [ -z "$dirs" ]; then
+    dirs=$directories
+fi
+
+for dir in $dirs; do
+    [ ! -d "$dir" ] && continue
+    echo Setting permissions in $dir...
+    sudo chown -R $user:$group $dir
+    sudo chmod -R u=rw,+X,g=rw,+X $dir
+    sudo find $dir -type d -exec chmod g+rws {} \;
+done

bin/setup_local_wsgi.sh

-#!/usr/bin/env bash
-#
-# Generates deploy/local.wsgi and settings/env/local.py for a given
-# environment
-#
-# To be run in an activated django-environments setting, i.e.
-# $PROJECT_ROOT and $DJANGO_PROJECT must be set correctly.
-
-env=$1
-local=local # Identifier for local configuration
-
-# Check arguments
-[ -z "$env" ] && echo "Usage: $0 <environment>" 1>&2 && exit 1
-
-# The root of the project should exist, of course
-[ -z "$PROJECT_ROOT" ] && \
-    echo "Variable \$PROJECT_ROOT not set or empty" 1>&2 && exit 1
-[ ! -d "$PROJECT_ROOT" ] && \
-     echo "Variable \$PROJECT_ROOT does not point to a readable directory" 1>&2 && exit 1
-
-# Check Django project as well
-[ -z "$DJANGO_PROJECT" ] && \
-    echo "Variable \$DJANGO_PROJECT not set or empty" 1>&2 && exit 1
-[ ! -d "$PROJECT_ROOT/$DJANGO_PROJECT" ] && \
-    echo "Variable \$DJANGO_PROJECT does not identify a readable directory within $PROJECT_ROOT" 1>&2 && \
-    exit 1
-
-# WSGI symlink
-
-deploy_dir=$PROJECT_ROOT/$DJANGO_PROJECT/deploy
-wsgi_target=$deploy_dir/$env.wsgi
-wsgi_local=$deploy_dir/$local.wsgi
-[ ! -f "$wsgi_target" ] && echo "$wsgi_target not found - exiting" 1>&2 && exit 1
-
-rm -f $wsgi_local
-ln -s $env.wsgi $wsgi_local
-[ ! $? -eq 0 ] && echo "Error creating symlink $wsgi_local" 1>&2 && exit 1
-echo "Link $local.wsgi to $wsgi_target created" 1>&2
-
-# Settings python file
-
-settings_dir=$PROJECT_ROOT/$DJANGO_PROJECT/settings/env
-settings_target=$settings_dir/$env.py
-settings_local=$PROJECT_ROOT/$DJANGO_PROJECT/settings/env/$local.py
-[ ! -f "$settings_target" ] && echo "$settings_target not found - exiting" 1>&2 && exit 1
-
-cat > $settings_local << EOF
-from $env import *
-
-# You can set stuff you don't wish to store anywhere else here, like:
-# DATABASES['default']['PASSWORD'] = 'secret'
-EOF
-echo "$settings_local created" 1>&2

distribute_setup.py

-#!python
-"""Bootstrap distribute installation
-
-If you want to use setuptools in your package's setup.py, just include this
-file in the same directory with it, and add this to the top of your setup.py::
-
-    from distribute_setup import use_setuptools
-    use_setuptools()
-
-If you want to require a specific version of setuptools, set a download
-mirror, or use an alternate download directory, you can do so by supplying
-the appropriate options to ``use_setuptools()``.
-
-This file can also be run as a script to install or upgrade setuptools.
-"""
-import os
-import sys
-import time
-import fnmatch
-import tempfile
-import tarfile
-from distutils import log
-
-try:
-    from site import USER_SITE
-except ImportError:
-    USER_SITE = None
-
-try:
-    import subprocess
-
-    def _python_cmd(*args):
-        args = (sys.executable,) + args
-        return subprocess.call(args) == 0
-
-except ImportError:
-    # will be used for python 2.3
-    def _python_cmd(*args):
-        args = (sys.executable,) + args
-        # quoting arguments if windows
-        if sys.platform == 'win32':
-            def quote(arg):
-                if ' ' in arg:
-                    return '"%s"' % arg
-                return arg
-            args = [quote(arg) for arg in args]
-        return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
-
-DEFAULT_VERSION = "0.6.14"
-DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
-SETUPTOOLS_FAKED_VERSION = "0.6c11"
-
-SETUPTOOLS_PKG_INFO = """\
-Metadata-Version: 1.0
-Name: setuptools
-Version: %s
-Summary: xxxx
-Home-page: xxx
-Author: xxx
-Author-email: xxx
-License: xxx
-Description: xxx
-""" % SETUPTOOLS_FAKED_VERSION
-
-
-def _install(tarball):
-    # extracting the tarball
-    tmpdir = tempfile.mkdtemp()
-    log.warn('Extracting in %s', tmpdir)
-    old_wd = os.getcwd()
-    try:
-        os.chdir(tmpdir)
-        tar = tarfile.open(tarball)
-        _extractall(tar)
-        tar.close()
-
-        # going in the directory
-        subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
-        os.chdir(subdir)
-        log.warn('Now working in %s', subdir)
-
-        # installing
-        log.warn('Installing Distribute')
-        if not _python_cmd('setup.py', 'install'):
-            log.warn('Something went wrong during the installation.')
-            log.warn('See the error message above.')
-    finally:
-        os.chdir(old_wd)
-
-
-def _build_egg(egg, tarball, to_dir):
-    # extracting the tarball
-    tmpdir = tempfile.mkdtemp()
-    log.warn('Extracting in %s', tmpdir)
-    old_wd = os.getcwd()
-    try:
-        os.chdir(tmpdir)
-        tar = tarfile.open(tarball)
-        _extractall(tar)
-        tar.close()
-
-        # going in the directory
-        subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
-        os.chdir(subdir)
-        log.warn('Now working in %s', subdir)
-
-        # building an egg
-        log.warn('Building a Distribute egg in %s', to_dir)
-        _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
-
-    finally:
-        os.chdir(old_wd)
-    # returning the result
-    log.warn(egg)
-    if not os.path.exists(egg):
-        raise IOError('Could not build the egg.')
-
-
-def _do_download(version, download_base, to_dir, download_delay):
-    egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg'
-                       % (version, sys.version_info[0], sys.version_info[1]))
-    if not os.path.exists(egg):
-        tarball = download_setuptools(version, download_base,
-                                      to_dir, download_delay)
-        _build_egg(egg, tarball, to_dir)
-    sys.path.insert(0, egg)
-    import setuptools
-    setuptools.bootstrap_install_from = egg
-
-
-def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
-                   to_dir=os.curdir, download_delay=15, no_fake=True):
-    # making sure we use the absolute path
-    to_dir = os.path.abspath(to_dir)
-    was_imported = 'pkg_resources' in sys.modules or \
-        'setuptools' in sys.modules
-    try:
-        try:
-            import pkg_resources
-            if not hasattr(pkg_resources, '_distribute'):
-                if not no_fake:
-                    _fake_setuptools()
-                raise ImportError
-        except ImportError:
-            return _do_download(version, download_base, to_dir, download_delay)
-        try:
-            pkg_resources.require("distribute>="+version)
-            return
-        except pkg_resources.VersionConflict:
-            e = sys.exc_info()[1]
-            if was_imported:
-                sys.stderr.write(
-                "The required version of distribute (>=%s) is not available,\n"
-                "and can't be installed while this script is running. Please\n"
-                "install a more recent version first, using\n"
-                "'easy_install -U distribute'."
-                "\n\n(Currently using %r)\n" % (version, e.args[0]))
-                sys.exit(2)
-            else:
-                del pkg_resources, sys.modules['pkg_resources']    # reload ok
-                return _do_download(version, download_base, to_dir,
-                                    download_delay)
-        except pkg_resources.DistributionNotFound:
-            return _do_download(version, download_base, to_dir,
-                                download_delay)
-    finally:
-        if not no_fake:
-            _create_fake_setuptools_pkg_info(to_dir)
-
-def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
-                        to_dir=os.curdir, delay=15):
-    """Download distribute from a specified location and return its filename
-
-    `version` should be a valid distribute version number that is available
-    as an egg for download under the `download_base` URL (which should end
-    with a '/'). `to_dir` is the directory where the egg will be downloaded.
-    `delay` is the number of seconds to pause before an actual download
-    attempt.
-    """
-    # making sure we use the absolute path
-    to_dir = os.path.abspath(to_dir)
-    try:
-        from urllib.request import urlopen
-    except ImportError:
-        from urllib2 import urlopen
-    tgz_name = "distribute-%s.tar.gz" % version
-    url = download_base + tgz_name
-    saveto = os.path.join(to_dir, tgz_name)
-    src = dst = None
-    if not os.path.exists(saveto):  # Avoid repeated downloads
-        try:
-            log.warn("Downloading %s", url)
-            src = urlopen(url)
-            # Read/write all in one block, so we don't create a corrupt file
-            # if the download is interrupted.
-            data = src.read()
-            dst = open(saveto, "wb")
-            dst.write(data)
-        finally:
-            if src:
-                src.close()
-            if dst:
-                dst.close()
-    return os.path.realpath(saveto)
-
-def _no_sandbox(function):
-    def __no_sandbox(*args, **kw):
-        try:
-            from setuptools.sandbox import DirectorySandbox
-            if not hasattr(DirectorySandbox, '_old'):
-                def violation(*args):
-                    pass
-                DirectorySandbox._old = DirectorySandbox._violation
-                DirectorySandbox._violation = violation
-                patched = True
-            else:
-                patched = False
-        except ImportError:
-            patched = False
-
-        try:
-            return function(*args, **kw)
-        finally:
-            if patched:
-                DirectorySandbox._violation = DirectorySandbox._old
-                del DirectorySandbox._old
-
-    return __no_sandbox
-
-def _patch_file(path, content):
-    """Will backup the file then patch it"""
-    existing_content = open(path).read()
-    if existing_content == content:
-        # already patched
-        log.warn('Already patched.')
-        return False
-    log.warn('Patching...')
-    _rename_path(path)
-    f = open(path, 'w')
-    try:
-        f.write(content)
-    finally:
-        f.close()
-    return True
-
-_patch_file = _no_sandbox(_patch_file)
-
-def _same_content(path, content):
-    return open(path).read() == content
-
-def _rename_path(path):
-    new_name = path + '.OLD.%s' % time.time()
-    log.warn('Renaming %s into %s', path, new_name)
-    os.rename(path, new_name)
-    return new_name
-
-def _remove_flat_installation(placeholder):
-    if not os.path.isdir(placeholder):
-        log.warn('Unkown installation at %s', placeholder)
-        return False
-    found = False
-    for file in os.listdir(placeholder):
-        if fnmatch.fnmatch(file, 'setuptools*.egg-info'):
-            found = True
-            break
-    if not found:
-        log.warn('Could not locate setuptools*.egg-info')
-        return
-
-    log.warn('Removing elements out of the way...')
-    pkg_info = os.path.join(placeholder, file)
-    if os.path.isdir(pkg_info):
-        patched = _patch_egg_dir(pkg_info)
-    else:
-        patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO)
-
-    if not patched:
-        log.warn('%s already patched.', pkg_info)
-        return False
-    # now let's move the files out of the way
-    for element in ('setuptools', 'pkg_resources.py', 'site.py'):
-        element = os.path.join(placeholder, element)
-        if os.path.exists(element):
-            _rename_path(element)
-        else:
-            log.warn('Could not find the %s element of the '
-                     'Setuptools distribution', element)
-    return True
-
-_remove_flat_installation = _no_sandbox(_remove_flat_installation)
-
-def _after_install(dist):
-    log.warn('After install bootstrap.')
-    placeholder = dist.get_command_obj('install').install_purelib
-    _create_fake_setuptools_pkg_info(placeholder)
-
-def _create_fake_setuptools_pkg_info(placeholder):
-    if not placeholder or not os.path.exists(placeholder):
-        log.warn('Could not find the install location')
-        return
-    pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
-    setuptools_file = 'setuptools-%s-py%s.egg-info' % \
-            (SETUPTOOLS_FAKED_VERSION, pyver)
-    pkg_info = os.path.join(placeholder, setuptools_file)
-    if os.path.exists(pkg_info):
-        log.warn('%s already exists', pkg_info)
-        return
-
-    log.warn('Creating %s', pkg_info)
-    f = open(pkg_info, 'w')
-    try:
-        f.write(SETUPTOOLS_PKG_INFO)
-    finally:
-        f.close()
-
-    pth_file = os.path.join(placeholder, 'setuptools.pth')
-    log.warn('Creating %s', pth_file)
-    f = open(pth_file, 'w')
-    try:
-        f.write(os.path.join(os.curdir, setuptools_file))
-    finally:
-        f.close()
-
-_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info)
-
-def _patch_egg_dir(path):
-    # let's check if it's already patched
-    pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
-    if os.path.exists(pkg_info):
-        if _same_content(pkg_info, SETUPTOOLS_PKG_INFO):
-            log.warn('%s already patched.', pkg_info)
-            return False
-    _rename_path(path)
-    os.mkdir(path)
-    os.mkdir(os.path.join(path, 'EGG-INFO'))
-    pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
-    f = open(pkg_info, 'w')
-    try:
-        f.write(SETUPTOOLS_PKG_INFO)
-    finally:
-        f.close()
-    return True
-
-_patch_egg_dir = _no_sandbox(_patch_egg_dir)
-
-def _before_install():
-    log.warn('Before install bootstrap.')
-    _fake_setuptools()
-
-
-def _under_prefix(location):
-    if 'install' not in sys.argv:
-        return True
-    args = sys.argv[sys.argv.index('install')+1:]
-    for index, arg in enumerate(args):
-        for option in ('--root', '--prefix'):
-            if arg.startswith('%s=' % option):
-                top_dir = arg.split('root=')[-1]
-                return location.startswith(top_dir)
-            elif arg == option:
-                if len(args) > index:
-                    top_dir = args[index+1]
-                    return location.startswith(top_dir)
-        if arg == '--user' and USER_SITE is not None:
-            return location.startswith(USER_SITE)
-    return True
-
-
-def _fake_setuptools():
-    log.warn('Scanning installed packages')
-    try:
-        import pkg_resources
-    except ImportError:
-        # we're cool
-        log.warn('Setuptools or Distribute does not seem to be installed.')
-        return
-    ws = pkg_resources.working_set
-    try:
-        setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools',
-                                  replacement=False))
-    except TypeError:
-        # old distribute API
-        setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
-
-    if setuptools_dist is None:
-        log.warn('No setuptools distribution found')
-        return
-    # detecting if it was already faked
-    setuptools_location = setuptools_dist.location
-    log.warn('Setuptools installation detected at %s', setuptools_location)
-
-    # if --root or --preix was provided, and if
-    # setuptools is not located in them, we don't patch it
-    if not _under_prefix(setuptools_location):
-        log.warn('Not patching, --root or --prefix is installing Distribute'
-                 ' in another location')
-        return
-
-    # let's see if its an egg
-    if not setuptools_location.endswith('.egg'):
-        log.warn('Non-egg installation')
-        res = _remove_flat_installation(setuptools_location)
-        if not res:
-            return
-    else:
-        log.warn('Egg installation')
-        pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
-        if (os.path.exists(pkg_info) and
-            _same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
-            log.warn('Already patched.')
-            return
-        log.warn('Patching...')
-        # let's create a fake egg replacing setuptools one
-        res = _patch_egg_dir(setuptools_location)
-        if not res:
-            return
-    log.warn('Patched done.')
-    _relaunch()
-
-
-def _relaunch():
-    log.warn('Relaunching...')
-    # we have to relaunch the process
-    # pip marker to avoid a relaunch bug
-    if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']:
-        sys.argv[0] = 'setup.py'
-    args = [sys.executable] + sys.argv
-    sys.exit(subprocess.call(args))
-
-
-def _extractall(self, path=".", members=None):
-    """Extract all members from the archive to the current working
-       directory and set owner, modification time and permissions on
-       directories afterwards. `path' specifies a different directory
-       to extract to. `members' is optional and must be a subset of the
-       list returned by getmembers().
-    """
-    import copy
-    import operator
-    from tarfile import ExtractError
-    directories = []
-
-    if members is None:
-        members = self
-
-    for tarinfo in members:
-        if tarinfo.isdir():
-            # Extract directories with a safe mode.
-            directories.append(tarinfo)
-            tarinfo = copy.copy(tarinfo)
-            tarinfo.mode = 448 # decimal for oct 0700
-        self.extract(tarinfo, path)
-
-    # Reverse sort directories.
-    if sys.version_info < (2, 4):
-        def sorter(dir1, dir2):
-            return cmp(dir1.name, dir2.name)
-        directories.sort(sorter)
-        directories.reverse()
-    else:
-        directories.sort(key=operator.attrgetter('name'), reverse=True)
-
-    # Set correct owner, mtime and filemode on directories.
-    for tarinfo in directories:
-        dirpath = os.path.join(path, tarinfo.name)
-        try:
-            self.chown(tarinfo, dirpath)
-            self.utime(tarinfo, dirpath)
-            self.chmod(tarinfo, dirpath)
-        except ExtractError:
-            e = sys.exc_info()[1]
-            if self.errorlevel > 1:
-                raise
-            else:
-                self._dbg(1, "tarfile: %s" % e)
-
-
-def main(argv, version=DEFAULT_VERSION):
-    """Install or upgrade setuptools and EasyInstall"""
-    tarball = download_setuptools()
-    _install(tarball)
-
-
-if __name__ == '__main__':
-    main(sys.argv[1:])

etc/settings/__init__.py

-from etc.settings.generic import *
-from etc.settings.database import *
-from etc.settings.log import *
-from etc.settings.middleware import *
-from etc.settings.template import *
-from etc.settings.apps.compressor import *
+from .generic import *
+from .cache import *
+from .database import *
+from .log import *
+from .template import *
+from .apps.compressor import *

etc/settings/cache.py

+CACHES = {
+    'memcached': {
+        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+        'LOCATION': '127.0.0.1:11211',
+    },
+    'database': {
+        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
+        'LOCATION': '_cache',
+    },
+    'dummy': {
+        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
+    }
+}
+CACHES['default'] = CACHES['database']

etc/settings/database.py

 DATABASE_NAME = PROJECT
 
 DATABASES_DEFAULT = {
-    'default_sqlite': {
+    'sqlite': {
         'ENGINE': 'django.db.backends.sqlite3',
-        'NAME': path.join(PROJECT_ROOT, 'db', '%s.sqlite3' % DJANGO_PROJECT),
+        'NAME': path.join(PROJECT_ROOT, 'db', '%s.sqlite3' % DATABASE_NAME),
     },
-    'default_mysql': {
+    'mysql': {
         'ENGINE': 'django.db.backends.mysql',
         'NAME': DATABASE_NAME,
         'USER': 'mysql',
     },
-    'default_postgres': {
+    'postgres': {
         'ENGINE': 'django.db.backends.postgresql_psycopg2',
         'NAME': DATABASE_NAME,
         'USER': 'postgres',
 }
 
 DATABASES = {
-    'default': DATABASES_DEFAULT['default_' + \
-                                 environ.get('DJANGO_DATABASE_TYPE', 'sqlite')]
+    'default':
+        DATABASES_DEFAULT[environ.get('DJANGO_DATABASE_TYPE', 'sqlite')]
 }

etc/settings/generic.py

 
 DEFAULT_FROM_EMAIL = 'g0j0 admin <%s>' % ADMINS[0][1]
 
-DEBUG = False
-TEMPLATE_DEBUG = DEBUG
+DEBUG = TEMPLATE_DEBUG = False
 
 TIME_ZONE = 'Europe/Amsterdam'
 
 STATIC_ID = 'static'
 STATIC_ROOT = path.join(PROJECT_ROOT, STATIC_ID)
 STATIC_URL = '/%s/' % STATIC_ID
+
 MEDIA_ID = 'media'
 MEDIA_ROOT = path.join(PROJECT_ROOT, MEDIA_ID)
 MEDIA_URL = '/%s/' % MEDIA_ID
 
 ROOT_URLCONF = DJANGO_PROJECT + '.urls'
 
-FIXTURE_DIRS = (
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
 )
 
-CACHES = {
-    'memcached': {
-        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
-        'LOCATION': '127.0.0.1:11211',
-    },
-    'database': {
-        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
-        'LOCATION': '_cache',
-    },
-    'dummy': {
-        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
-    }
-}
-CACHES['default'] = CACHES['database']
-
 SESSION_COOKIE_HTTPONLY = True

etc/settings/log.py

File contents unchanged.

etc/settings/middleware.py

-MIDDLEWARE_CLASSES_DEFAULT = (
-    'django.middleware.common.CommonMiddleware',
-    'django.contrib.sessions.middleware.SessionMiddleware',
-    'django.middleware.csrf.CsrfViewMiddleware',
-    'django.contrib.auth.middleware.AuthenticationMiddleware',
-    'django.contrib.messages.middleware.MessageMiddleware',
-)
-
-MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES_DEFAULT

etc/settings/template.py

     'django.template.loaders.app_directories.Loader',
 )
 
-TEMPLATE_LOADERS = TEMPLATE_LOADERS_DEFAULT
-
 TEMPLATE_LOADERS_CACHED = (
     ('django.template.loaders.cached.Loader', TEMPLATE_LOADERS_DEFAULT),
 )
 
-TEMPLATE_CONTEXT_PROCESSORS_DEFAULT = (
+TEMPLATE_LOADERS = TEMPLATE_LOADERS_CACHED
+
+TEMPLATE_CONTEXT_PROCESSORS = (
     'django.contrib.auth.context_processors.auth',
     'django.core.context_processors.debug',
     'django.core.context_processors.i18n',
     'django.contrib.messages.context_processors.messages',
     'g0j0.context_processors.settings_proxy',
 )
-
-TEMPLATE_CONTEXT_PROCESSORS = TEMPLATE_CONTEXT_PROCESSORS_DEFAULT
-from django.conf.urls.defaults import patterns, include, url, handler404, handler500
-handler404, handler500 # Keep pyflakes happy...
+from django.conf.urls.defaults import url, include, patterns
+from django.conf.urls.i18n import i18n_patterns
 from django.contrib import admin
-from django.contrib import databrowse
 from django.conf import settings
 
 
-__all__ = ('default_patterns', 'patterns', 'include', 'url', 'handler404', 'handler500')
+__all__ = ('default_patterns', 'default_i18n_patterns')
 
 admin.autodiscover()
 
-default_patterns = patterns('',
-    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+_patterns = (
     url(r'^admin/', include(admin.site.urls)),
-    url(r'^databrowse/(.*)', databrowse.site.root),
     url(r'^%s$' % settings.LOGIN_URL[1:], 'django.contrib.auth.views.login',
          {'template_name': 'admin/login.html'})
 )
+
+default_patterns = patterns('', *_patterns)
+default_i18n_patterns = i18n_patterns('', *_patterns)

requirements/libs-dev.txt

+--requirement=libs-prd.txt
+PyYAML
+docutils
+Sphinx
+pyflakes
+Pygments
+pysmell
+django-debug-toolbar

requirements/libs-development.txt

-# Example requirements for development
-django-environments # whoohoo!
-Django
-PyYAML
-docutils
-Sphinx
-pyflakes
-Pygments
-pysmell
-django-debug-toolbar

requirements/libs-prd.txt

+Django

requirements/libs-production.txt

-# Example requirements for production
-Django==1.2.1
-PyYAML==3.09

setup.py

-from distribute_setup import use_setuptools
-use_setuptools()
-# See http://packages.python.org/distribute/setuptools.html#using-setuptools-without-bundling-it
-
-from os import path, listdir
-
-# from distutils.core import setup
-import setuptools; print setuptools.__file__
-from setuptools import setup, find_packages
-# exit()
-
-
-# XXX TODO only include executable files here, and try to include the other files with MANIFEST.in
-bin_dirname = 'bin'
-bin_dir = path.join(path.dirname(path.abspath(__file__)), bin_dirname)
-scripts = [path.join(bin_dirname, script) for script in listdir(bin_dir)]
-
-setup(
-    name='django-environments',
-    version='0.1',
-    description='Django Environments',
-    url='http://goeiejongens.nl/',
-    author='Goeie Jongens',
-    author_email='wij@goeiejongens.nl',
-    packages=[],
-    scripts=scripts,
-)