1991-06-04 17:36:54 -03:00
|
|
|
#! /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:
|
1991-07-01 15:22:34 -03:00
|
|
|
name = path.join(dirname, name)
|
1991-06-04 17:36:54 -03:00
|
|
|
try:
|
|
|
|
linkto = posix.readlink(name)
|
1992-01-01 15:35:13 -04:00
|
|
|
if linkto[:n] == pattern:
|
1991-06-04 17:36:54 -03:00
|
|
|
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:])
|