summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/findlinksto.py
blob: a8051c1edd00a550b0da46731d04f81932d163f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! /usr/local/python

# findlinksto
#
# find symbolic links to a given path

import posix, path, sys

def visit(pattern, dirname, names):
	if path.islink(dirname):
		names[:] = []
		return
	if path.ismount(dirname):
		print 'descend into', dirname
	n = len(pattern)
	for name in names:
		name = path.join(dirname, name)
		try:
			linkto = posix.readlink(name)
			if linkto[:n] == pattern:
				print name, '->', linkto
		except posix.error:
			pass

def main(pattern, args):
	for dirname in args:
		path.walk(dirname, visit, pattern)

main(sys.argv[1], sys.argv[2:])