annotate python/which.py @ 194:931bc3353f75

add simpleconf.py
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 23 Jan 2012 20:41:10 -0800
parents b91750a108b2
children e4221e45d6c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
176
b91750a108b2 make which.py work
Jeff Hammel <jhammel@mozilla.com>
parents: 170
diff changeset
1 #!/usr/bin/env python
b91750a108b2 make which.py work
Jeff Hammel <jhammel@mozilla.com>
parents: 170
diff changeset
2
b91750a108b2 make which.py work
Jeff Hammel <jhammel@mozilla.com>
parents: 170
diff changeset
3 import os
b91750a108b2 make which.py work
Jeff Hammel <jhammel@mozilla.com>
parents: 170
diff changeset
4 import sys
b91750a108b2 make which.py work
Jeff Hammel <jhammel@mozilla.com>
parents: 170
diff changeset
5
170
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 def findInPath(fileName, path=os.environ['PATH']):
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 """python equivalent of which; should really be in the stdlib"""
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 dirs = path.split(os.pathsep)
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 for dir in dirs:
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 if os.path.isfile(os.path.join(dir, fileName)):
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 return os.path.join(dir, fileName)
176
b91750a108b2 make which.py work
Jeff Hammel <jhammel@mozilla.com>
parents: 170
diff changeset
12 if os.path.isfile(os.path.join(dir, fileName + ".exe")):
b91750a108b2 make which.py work
Jeff Hammel <jhammel@mozilla.com>
parents: 170
diff changeset
13 return os.path.join(dir, fileName + ".exe")
170
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 if __name__ == '__main__':
3e52d6bcac99 add the which thingy
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 for i in sys.argv[1:]:
176
b91750a108b2 make which.py work
Jeff Hammel <jhammel@mozilla.com>
parents: 170
diff changeset
17 print findInPath(i)