diff options
author | Guido van Rossum <guido@python.org> | 1991-06-04 20:36:54 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-06-04 20:36:54 (GMT) |
commit | ec758ead391daa2ce0e5697aa0e67ec3ba0f37af (patch) | |
tree | 7f2d186afd41d797882d5b5be3330e921804ebe9 /Tools/scripts/findlinksto.py | |
parent | 0481447f4135c11d42ae25f55696af8e8d52fe74 (diff) | |
download | cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.zip cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.tar.gz cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.tar.bz2 |
Initial revision
Diffstat (limited to 'Tools/scripts/findlinksto.py')
-rwxr-xr-x | Tools/scripts/findlinksto.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Tools/scripts/findlinksto.py b/Tools/scripts/findlinksto.py new file mode 100755 index 0000000..6a2a75b --- /dev/null +++ b/Tools/scripts/findlinksto.py @@ -0,0 +1,29 @@ +#! /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: + name = path.cat(dirname, name) + try: + linkto = posix.readlink(name) + if linkto[:n] = pattern: + 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:]) |