comparison python/which.py @ 176:b91750a108b2

make which.py work
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 31 Oct 2011 10:48:57 -0700
parents 3e52d6bcac99
children e4221e45d6c1
comparison
equal deleted inserted replaced
175:081614c468b8 176:b91750a108b2
1 #!/usr/bin/env python
2
3 import os
4 import sys
5
1 def findInPath(fileName, path=os.environ['PATH']): 6 def findInPath(fileName, path=os.environ['PATH']):
2 """python equivalent of which; should really be in the stdlib""" 7 """python equivalent of which; should really be in the stdlib"""
3 dirs = path.split(os.pathsep) 8 dirs = path.split(os.pathsep)
4 for dir in dirs: 9 for dir in dirs:
5 if os.path.isfile(os.path.join(dir, fileName)): 10 if os.path.isfile(os.path.join(dir, fileName)):
6 return os.path.join(dir, fileName) 11 return os.path.join(dir, fileName)
7 if mozinfo.isWin: 12 if os.path.isfile(os.path.join(dir, fileName + ".exe")):
8 if os.path.isfile(os.path.join(dir, fileName + ".exe")): 13 return os.path.join(dir, fileName + ".exe")
9 return os.path.join(dir, fileName + ".exe")
10 14
11 if __name__ == '__main__': 15 if __name__ == '__main__':
12 for i in sys.argv[1:]: 16 for i in sys.argv[1:]:
13 print findInPath(i) 17 print findInPath(i)