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/which.py | |
parent | 0481447f4135c11d42ae25f55696af8e8d52fe74 (diff) | |
download | cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.zip cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.tar.gz cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.tar.bz2 |
Initial revision
Diffstat (limited to 'Tools/scripts/which.py')
-rwxr-xr-x | Tools/scripts/which.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Tools/scripts/which.py b/Tools/scripts/which.py new file mode 100755 index 0000000..b9b888b --- /dev/null +++ b/Tools/scripts/which.py @@ -0,0 +1,44 @@ +#! /usr/local/python + +# Variant of "which". +# On stderr, near and total misses are reported. + +import sys, posix, string, path +from stat import * + +def msg(str): + sys.stderr.write(str + '\n') + +pathlist = string.splitfields(posix.environ['PATH'], ':') + +sts = 0 + +for prog in sys.argv[1:]: + ident = () + for dir in pathlist: + file = path.cat(dir, prog) + try: + st = posix.stat(file) + if S_ISREG(st[ST_MODE]): + mode = S_IMODE(st[ST_MODE]) + if mode % 2 or mode/8 % 2 or mode/64 % 2: + if ident: + if st[:3] = ident: + s = ': same as ' + else: + s = ': also ' + msg(prog + s + file) + else: + print file + ident = st[:3] + else: + msg(file + ': not executable') + else: + msg(file + ': not a disk file') + except posix.error: + pass + if not ident: + msg(prog + ': not found') + sts = 1 + +sys.exit(sts) |