Mercurial > hg > config
comparison python/which.py @ 218:e4221e45d6c1
update install script
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 06 Apr 2012 16:41:05 -0700 |
parents | b91750a108b2 |
children | e7ab4cf29f7b |
comparison
equal
deleted
inserted
replaced
217:4ad8bce17e85 | 218:e4221e45d6c1 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import os | 3 import os |
4 import sys | 4 import sys |
5 | 5 |
6 def findInPath(fileName, path=os.environ['PATH']): | 6 def which(fileName, path=os.environ['PATH']): |
7 """python equivalent of which; should really be in the stdlib""" | 7 """python equivalent of which; should really be in the stdlib""" |
8 dirs = path.split(os.pathsep) | 8 dirs = path.split(os.pathsep) |
9 for dir in dirs: | 9 for dir in dirs: |
10 if os.path.isfile(os.path.join(dir, fileName)): | 10 if os.path.isfile(os.path.join(dir, fileName)): |
11 return os.path.join(dir, fileName) | 11 return os.path.join(dir, fileName) |
12 if os.path.isfile(os.path.join(dir, fileName + ".exe")): | 12 if os.path.isfile(os.path.join(dir, fileName + ".exe")): |
13 return os.path.join(dir, fileName + ".exe") | 13 return os.path.join(dir, fileName + ".exe") |
14 | 14 |
15 if __name__ == '__main__': | 15 if __name__ == '__main__': |
16 for i in sys.argv[1:]: | 16 for i in sys.argv[1:]: |
17 print findInPath(i) | 17 print which(i) |