0
0
mirror of https://github.com/python/cpython.git synced 2024-11-25 01:20:47 +01:00
cpython/Tools/scripts/findlinksto.py

30 lines
563 B
Python
Raw Normal View History

1991-06-04 22:36:54 +02:00
#! /usr/local/python
# 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:])