#!/usr/bin/env python import getopt, os, sys # The site-packages directory. site_packages = os.path.join(os.path.dirname(os.__file__), 'site-packages') # The path where your Django branches are. django_path = os.path.join(os.environ['HOME'], 'django') def usage(): print """Usage: chdjango.py [-p ] Where is the directory of the Django distribution located within (defaults to ~/django, but may be customized with the `-p` option). For example, if you nave `queryset-refactor` and `newforms-admin` in in `/opt/django`, then `chdjango.py -p /opt/django newforms-admin` will set newforms-admin to be the Django distribution used in Python. """ if __name__=='__main__': try: opt, args = getopt.getopt(sys.argv[1:], 'p:', ['path']) except Exception, msg: sys.stderr.write('%s\n' % msg) usage() sys.exit(1) if len(args) != 1: usage() sys.exit(2) # Seeing if the path option was specified. for o, a in opt: if o in ('-p', '--path'): django_path = a # Getting the new Django path, and making sure it exists. dj_pth = os.path.join(django_path, args[0]) if not os.path.isdir(dj_pth): sys.stderr.write('ERROR: The Django path ("%s") does not exist.\n' % dj_pth) sys.exit(3) # Writing `django.pth` in the site-packages directory. fh = open(os.path.join(site_packages, 'django.pth'), 'w') fh.write('%s\n' % dj_pth) fh.close()