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