1993-04-01 16:50:35 -04:00
|
|
|
#! /usr/local/bin/python
|
1991-06-04 17:36:54 -03:00
|
|
|
|
|
|
|
# findlinksto
|
|
|
|
#
|
|
|
|
# find symbolic links to a given path
|
|
|
|
|
1992-03-30 07:14:36 -04:00
|
|
|
import os, sys
|
1991-06-04 17:36:54 -03:00
|
|
|
|
|
|
|
def visit(pattern, dirname, names):
|
1992-03-30 07:14:36 -04:00
|
|
|
if os.path.islink(dirname):
|
1991-06-04 17:36:54 -03:00
|
|
|
names[:] = []
|
|
|
|
return
|
1992-03-30 07:14:36 -04:00
|
|
|
if os.path.ismount(dirname):
|
1991-06-04 17:36:54 -03:00
|
|
|
print 'descend into', dirname
|
|
|
|
n = len(pattern)
|
|
|
|
for name in names:
|
1992-03-30 07:14:36 -04:00
|
|
|
name = os.path.join(dirname, name)
|
1991-06-04 17:36:54 -03:00
|
|
|
try:
|
1992-03-30 07:14:36 -04:00
|
|
|
linkto = os.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
|
1992-03-30 07:14:36 -04:00
|
|
|
except os.error:
|
1991-06-04 17:36:54 -03:00
|
|
|
pass
|
|
|
|
|
|
|
|
def main(pattern, args):
|
|
|
|
for dirname in args:
|
1992-03-30 07:14:36 -04:00
|
|
|
os.path.walk(dirname, visit, pattern)
|
1991-06-04 17:36:54 -03:00
|
|
|
|
|
|
|
main(sys.argv[1], sys.argv[2:])
|