annotate python/which.py @ 222:d963d5a7e543

https://bugzilla.mozilla.org/show_bug.cgi?id=754703
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 14 May 2012 13:06:33 -0700
parents e4221e45d6c1
children e7ab4cf29f7b
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
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 176
diff changeset
6 def which(fileName, path=os.environ['PATH']):
170
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:]:
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 176
diff changeset
17 print which(i)