]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Tools/scripts/which.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Tools / scripts / which.py
CommitLineData
4710c53d 1#! /usr/bin/env python\r
2\r
3# Variant of "which".\r
4# On stderr, near and total misses are reported.\r
5# '-l<flags>' argument adds ls -l<flags> of each file found.\r
6\r
7import sys\r
8if sys.path[0] in (".", ""): del sys.path[0]\r
9\r
10import sys, os\r
11from stat import *\r
12\r
13def msg(str):\r
14 sys.stderr.write(str + '\n')\r
15\r
16def main():\r
17 pathlist = os.environ['PATH'].split(os.pathsep)\r
18\r
19 sts = 0\r
20 longlist = ''\r
21\r
22 if sys.argv[1:] and sys.argv[1][:2] == '-l':\r
23 longlist = sys.argv[1]\r
24 del sys.argv[1]\r
25\r
26 for prog in sys.argv[1:]:\r
27 ident = ()\r
28 for dir in pathlist:\r
29 filename = os.path.join(dir, prog)\r
30 try:\r
31 st = os.stat(filename)\r
32 except os.error:\r
33 continue\r
34 if not S_ISREG(st[ST_MODE]):\r
35 msg(filename + ': not a disk file')\r
36 else:\r
37 mode = S_IMODE(st[ST_MODE])\r
38 if mode & 0111:\r
39 if not ident:\r
40 print filename\r
41 ident = st[:3]\r
42 else:\r
43 if st[:3] == ident:\r
44 s = 'same as: '\r
45 else:\r
46 s = 'also: '\r
47 msg(s + filename)\r
48 else:\r
49 msg(filename + ': not executable')\r
50 if longlist:\r
51 sts = os.system('ls ' + longlist + ' ' + filename)\r
52 if sts: msg('"ls -l" exit status: ' + repr(sts))\r
53 if not ident:\r
54 msg(prog + ': not found')\r
55 sts = 1\r
56\r
57 sys.exit(sts)\r
58\r
59if __name__ == '__main__':\r
60 main()\r