Swap between different Django versions

By Jessy

The development environment i’m using right now requires that we use a slightly older version of django than the current svn checkout I had installed on my machine. I went searching around for what people do when they have multiple versions of django they need to run, and came across a simple script written by Patrick Altman.

I figure a lot of people, like me, have to switch not just between different revisions of django, but between a vendor branch and a main branch. So, I added in a vendor branch option, cleaned it up a little bit, and stuck it in my bin/ directory. To switch to the our vendor branch, I can now type

~$ djangoswitch.sh vendor

To go back to the main branch checkout, i’d then type

~$ djangoswitch.sh main

For a specific revision number,

~$ djangoswitch.sh main 9000

will do the trick.

The script accomplishes its task by removing the existing version of django, checking out the version you requested, and then updating the appropriate symlinks for the django python module and the django-admin command. Ultimately, if you’re frequently switching between the same two versions of django (ie, django current and your company’s vendor branch, for example), then it might make more sense to leave the code and just switch your symlinks. But i dont actually switch that often, django isnt that big, and this will ensure my main branch checkouts are up-to-date. so, this will do just fine for now.

The text of the script is below, and you can download it here. Thanks to Patrick for doing most of the thinking :) .

#!/bin/bash                                                                                                                
 
# script to change between different versions of django by removing
# and installing a different checkout. also supports a vendor
# branch.                                                                                                                  
 
# usage: specify vendor or main on the command line, optionally giving
# a revision number if checking out from main:
# djangoswitch [vendor | main [revision]]                                                                                  
 
# your machine-specific paths
DJANGOPATH=/home/jessy/svnCheckouts/django # make sure this exists.
SITEPACKAGES=/usr/lib/python2.5/site-packages
VENDORBRANCH=http://YOUR/VENDOR/BRANCH/GOES/HERE
# you shouldnt need to change this unless django changes their svn url.
DJANGOSVN=http://code.djangoproject.com/svn/django/trunk/django
 
if [ -z "${1}" ]
then
    echo 'usage: djangoswitch [vendor | main [revision]]'
    exit
fi
 
if [ "${1}" == 'vendor' ]
then
    echo 'switching to vendor branch'
    CHECKOUT=$VENDORBRANCH
elif [ "${1}" == 'main' ]
then
    CHECKOUT=$DJANGOSVN
    echo 'switching to django main branch'
else
    echo 'usage: djangoswitch [vendor | main [revision]]'
    exit
fi
 
# set up the revision number. we really only care about the revision number
# for the main branch checkouts, but set up the variable for the
# vendor checkout anyway so the code below can be generic.
if [ -n "${2}" ]
then
    REV=$2
else
    REV=$(svn info $CHECKOUT | grep "Revision:" | sed 's/Revision: //')
fi
 
# be informative
echo 'checking out revision' $REV 'from' $CHECKOUT
 
# get ride of the old version, checkout the new version, and create
# necessary symlinks.
rm -rf $DJANGOPATH/$REV
svn co -r $REV $CHECKOUT $DJANGOPATH/$REV
sudo rm -rf $SITEPACKAGES/django
# these might or might not exist. suppress the error messages if they
# dont.
sudo rm /usr/bin/django-admin* 2>/dev/null
sudo rm /usr/local/bin/django-admin* 2>/dev/null
sudo ln -s $DJANGOPATH/$REV/ $SITEPACKAGES/django
sudo ln -s $DJANGOPATH/$REV/bin/django-admin.py /usr/local/bin/django-admin
echo 'Symlinks updated'
echo "Switch completed."
Tags: , , ,

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Archives

  • January 2010
  • November 2009
  • July 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • Site Feeds

    Posts
    Comments

    Marginal Structure Posts RSS feed

    Site Tags