This is a convenient script for those working with different branches of Django.  Place all of your branches in ~/django (e.g., ~/django/newforms-admin, ~/django/trunk) and you're ready to quickly change between them.  For example: chdjango.py trunk.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  | #!/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 <django_path>] <django_name>
  
  Where <django_name> is the directory of the Django distribution located
  within <django_path> (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()
 | 
More like this
- Add Toggle Switch Widget to Django Forms by OgliariNatan 1 month, 4 weeks ago
 - get_object_or_none by azwdevops 5 months, 2 weeks ago
 - Mask sensitive data from logger by agusmakmun 7 months, 2 weeks ago
 - Template tag - list punctuation for a list of items by shapiromatron 1 year, 9 months ago
 - JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 1 year, 9 months ago
 
Comments
Thanks for the snippet. It makes life super simple.
#
very useful.
#
Very good snippet.
#
Please login first before commenting.