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