#!/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 """ ## 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')