4 # USAGE: mass-link.py [--prepend-suffix SUFFIX] symbolic | hard SOURCEDIR DESTDIR FILES
6 # create hard or symbolic links to SOURCEDIR/FILES in DESTDIR
8 # if --prepend-suffix is specified, link to foo.bar will be called fooSUFFIX.bar
9 # shell-wildcard expansion is performed on FILES.
18 optlist, args = getopt.getopt (sys.argv[1:], '', ['prepend-suffix='])
19 link_type, source_dir, dest_dir = args[0:3]
24 if x[0] == '--prepend-suffix':
25 prepended_suffix = x[1]
28 def insert_suffix (p):
31 l[-2] += prepended_suffix
33 return p + prepended_suffix
35 insert_suffix = lambda p: p
37 if link_type == 'symbolic':
39 elif link_type == 'hard':
42 sys.stderr.write(sys.argv[0] + ': ' + link_type + ": wrong argument, expected 'symbolic' or 'hard'\n")
47 sourcefiles += (glob.glob (os.path.join (source_dir, pattern)))
49 destfiles = map (lambda f: os.path.join (dest_dir, insert_suffix (os.path.basename (f))), sourcefiles)
51 def force_link (src,dest):
52 if os.path.exists (dest):
53 os.system ('rm -rf ' + dest)
56 map (force_link, sourcefiles, destfiles)