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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 | #!/usr/bin/python
"""
This utility saves disk space if you have multiple Django installations on
your disk. It will hard link identical files between them.
Note that:
- you shouldn't edit any hard-linked files, or at least do it with a
copy-on-write capable editor
- you need Perl, Python >=2.4 and slocate installed and updatedb run recently
(usually run regularly from cron)
- you need the freedups.pl script available from
http://www.stearns.org/freedups/freedups.pl (this is my chosen duplicate
file hard linking utility after testing every one out there I could find)
- freedups.pl will create a md5sum-v1.cache file in your home directory
- ensure that you have write access to all Django installations
The script was tested on Ubuntu 6.10 Edgy. Modifications may be needed for
other operating systems -- please contribute improvements to the author.
Author: Antti Kaihola <akaihola@ambitone.com>
"""
## Configuration ##############################################################
##
## replace this with the path of freedups.pl on your system
##
FREEDUPS = '/usr/local/bin/freedups.pl'
##
###############################################################################
from subprocess import Popen, PIPE, call
from os.path import basename, exists
from sys import argv, exit, stdout
def out(s): stdout.write(s) ; stdout.flush()
selfpath = argv[0]
selfname = basename(selfpath)
out('%(selfname)s by Antti Kaihola 2007\n\n' % locals())
out('Searching all Django installations on the hard disk...')
try:
locate = Popen('locate -r /django/core/__init__.py$'.split(), stdout=PIPE)
django_dirs = [s[:-13] for s in locate.stdout]
except OSError, e:
exit('\nERROR: locate not found. Please install slocate and run updatedb.'
'\n (%s)' % e)
out(' Found %d.\n' % len(django_dirs))
out('Hard linking all identical files between Django installations...\n')
try:
if call(['perl', FREEDUPS, '-a'] + django_dirs) != 0:
exit("""
ERROR: freedups.pl couldn't be run. Please download\n
http://www.stearns.org/freedups/freedups.pl\n
and save it as\n
%(FREEDUPS)s\n
or indicate a different location by modifying the FREEDUPS variable in\n
%(selfpath)s""" % locals())
except OSError, e:
exit('ERROR: perl not found.\n'
' (%s)' % e)
out('Done. Have a good day!\n')
|
Comments