]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/mass-link.py
1f0ff074c6455675661990620651e6ca0682e34a
[lilypond.git] / buildscripts / mass-link.py
1 #!@PYTHON@
2 # mass-link.py
3
4 # USAGE:  mass-link.py   symbolic | hard   SOURCEDIR DESTDIR FILES
5 #
6 # create hard or symbolic links to SOURCEDIR/FILES in DESTDIR
7 #
8 # shell-wildcard expansion is performed on FILES.
9
10 print "mass_link.py"
11
12 import sys
13 import os
14 import glob
15
16 link_type, source_dir, dest_dir = sys.argv[1:4]
17 files = sys.argv[4:]
18
19 if link_type == 'symbolic':
20     link = os.symlink
21 elif link_type == 'hard':
22     link = os.link
23 else:
24     sys.stderr.write(sys.argv[0] + ': ' + link_type + ": wrong argument, expected 'symbolic' or 'hard'\n")
25     sys.exit (1)
26
27 sourcefiles = []
28 for pattern in files:
29     sourcefiles += (glob.glob (os.path.join (source_dir, pattern)))
30
31 destfiles = map (lambda f: os.path.join (dest_dir, os.path.basename (f)), sourcefiles)
32
33 def force_link (src,dest):
34     if os.path.exists (dest):
35         os.system ('rm -rf ' + dest)
36     link (src, dest)
37
38 map (force_link, sourcefiles, destfiles)