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