/usr/lib/python3/dist-packages/pyutilib/dev/lbin.py is in python3-pyutilib 5.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #!/usr/bin/env python
import sys
import os
from os.path import abspath, basename, dirname, exists, join
import subprocess
usage = """usage: lbin [-f][-v] <command> [...]
This script recurses up the current path, looking for 'bin' and
python/bin directories. If found, these directories are prepended to
the PATH environment path.
-f : [find_only] show results from 'which <command>' after PATH
expansion but do not run <command>
-v : [verbose] show results from 'which <command>' after PATH expansion
"""
def lbin(args):
verbose = False
find_only = False
if args and args[0] in ['-v','-f']:
if args[0] == '-v':
verbose = True
elif args[0] == '-f':
find_only = True
args.pop(0)
if args and args[0] in ['-v','-f']:
if args[0] == '-v':
verbose = True
elif args[0] == '-f':
find_only = True
args.pop(0)
if len(args) == 0:
print(usage)
return 1
try:
# On unix, the shell's reported PWD may be different from the '.'
# inode's absolute path (e.g., when the cwd was reached through
# symbolic links.) This is a trivial way to defer to the shell's
# notion of the cwd and quietly fall back on Python's getcwd() for
# non-unix environments.
curr = os.environ['PWD']
except:
curr = abspath(os.getcwd())
dirs = []
while os.sep in curr:
if exists( join(curr,"python") ):
dirs.append( join(curr,"python","bin") )
if exists( join(curr,"bin") ):
dirs.append( join(curr,"bin") )
if basename(curr) == "":
break
curr = dirname(curr)
dirs.append(os.environ["PATH"])
os.environ["PATH"] = os.pathsep.join(dirs)
#print os.environ["PATH"]
try:
if find_only:
if verbose:
return subprocess.call(['which','-a',args[0]])
else:
return subprocess.call(['which',args[0]])
if verbose:
print("Path search found the following instances of %s:" % args[0])
x = subprocess.call(['which',args[0]])
print("")
os.execvp(args[0], args)
#return subprocess.call(args)
except OSError:
err = sys.exc_info()[1]
print("ERROR executing command '%s': %s" % (' '.join(args), str(err)))
return err.errno
# The [console_scripts] entry point requires a function that takes no
# arguments
def main():
sys.exit( lbin( sys.argv[1:] ) )
if __name__ == '__main__':
main()
|