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()
|
Comments
Thanks for the snippet. It makes life super simple.
#
very useful.
#
Very good snippet.
#