root/trunk/hardlink_django_instances/hardlink_django_instances.py

Revision 101, 2.3 kB (checked in by akaihola, 2 years ago)

[hardlink_django_instances] Added this new utility.

  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2
3"""
4This utility saves disk space if you have multiple Django installations on
5your disk.  It will hard link identical files between them.
6
7Note 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
23The script was tested on Ubuntu 6.10 Edgy. Modifications may be needed for
24other operating systems -- please contribute improvements to the author.
25
26Author: Antti Kaihola <akaihola@ambitone.com>
27"""
28
29## Configuration ##############################################################
30##
31## replace this with the path of freedups.pl on your system
32##
33FREEDUPS = '/usr/local/bin/freedups.pl'
34##
35###############################################################################
36
37
38from subprocess import Popen, PIPE, call
39from os.path import basename, exists
40from sys import argv, exit, stdout
41def out(s): stdout.write(s) ; stdout.flush()
42
43selfpath = argv[0]
44selfname = basename(selfpath)
45
46out('%(selfname)s by Antti Kaihola 2007\n\n' % locals())
47out('Searching all Django installations on the hard disk...')
48
49try:
50    locate = Popen('locate -r /django/core/__init__.py$'.split(), stdout=PIPE)
51    django_dirs = [s[:-13] for s in locate.stdout]
52except OSError, e:
53    exit('\nERROR: locate not found. Please install slocate and run updatedb.'
54         '\n       (%s)' % e)
55
56out(' Found %d.\n' % len(django_dirs))
57out('Hard linking all identical files between Django installations...\n')
58
59try:
60    if call(['perl', FREEDUPS, '-a'] + django_dirs) != 0:
61        exit("""
62ERROR: freedups.pl couldn't be run. Please download\n
63  http://www.stearns.org/freedups/freedups.pl\n
64and save it as\n
65  %(FREEDUPS)s\n
66or indicate a different location by modifying the FREEDUPS variable in\n
67  %(selfpath)s""" % locals())
68except OSError, e:
69    exit('ERROR: perl not found.\n'
70         '       (%s)' % e)
71
72out('Done. Have a good day!\n')
Note: See TracBrowser for help on using the browser.