Muffinresearch Labs by Stuart Colville

Django: Switching between development branches | 2 Comments

Posted in Code, Linux/Unix on 9th March 2008, 7:47 pm by

Cyril and I have been using new forms admin for some stuff we are working on for fun whilst we are here at SXSWi. One of the issues is that if you’re developing several different Django sites you won’t necessary want to migrate away from trunk to migrate everything to one of the other branches that you’re trying out. Obviously at some point in the future work like the new forms admin branch and the queryset refactor branch will be merged back to trunk and you’ll want to switch back.

To make life a little easier I knocked up a simple shell script to switch between branches by changing the symlink to site-packages. This assumes you are already using the method which symlinks the svn source into site-packages.

As long as the branches are in the same directory this script will work as it simply creates a selection based on the branches contained withing the directory specifed in the constant “DJANGOBRANCHES”. Simply change the constant to meet your needs:

#!/usr/bin/env bash

DJANGOBRANCHES=/Users/muffin/django/
SITEPACKAGES=/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/

cd $DJANGOBRANCHES
echo 'Choose Django branch:'

select dir in *;
do
    if [ -n "$dir" ] && [ -d ${DJANGOBRANCHES}${dir}/ ]
    then
      rm -f ${SITEPACKAGES}django
      ln -s ${DJANGOBRANCHES}${dir}/django ${SITEPACKAGES}django
      break
    else
      echo "Error: You choice '$REPLY' does not correspond to a branch"
    fi
done

exit 0

Using the script is simple:

muffin@shiva muffin/django $ switch_django
Choose Django branch
1) django_src
2) newforms-admin
#? 2

Check the site-packages directory and you should see the correct branch is now sym-linked.

Post Tools

  • http://code.djangoproject.com/wiki/GeoDjango Justin Bronn

    I also created a script, chdjango, (in Python) for the same purpose. However, it lacks the interactive menu — I may have to borrow that idea.

  • http://muffinresearch.co.uk Stuart Colville

    @justin: Great minds think alike!

GNU screen: open tab in current working directory|(1)

A nice trick for having screen open a new tab in the same directory as the one you’re currently in. To use it add it to your .screenrc

# Open new window in current dir.
bind c stuff "screen -X chdir \$PWD;screen^M"
bind ^c stuff "screen -X chdir \$PWD;screen^M"

Hat tip: mteckert on SuperUser.com

Ubuntu: add-apt-repository: command not found|(3)

When you’re using a minimal Ubuntu install if you find the ‘add-apt-repository’ command is missing (it’s useful for adding PPAs and other repositories), then simply run:

sudo apt-get install python-software-properties

Photos on Flickr

© Copyright 2004-12 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.505s.