annotate python/which.py @ 694:ebca6d85213a

File "/usr/lib/python3/dist-packages/IPython/config/__init__.py", line 16, in <module> from .application import * File "/usr/lib/python3/dist-packages/IPython/config/application.py", line 31, in <module> from IPython.config.configurable import SingletonConfigurable File "/usr/lib/python3/dist-packages/IPython/config/configurable.py", line 33, in <module> from IPython.utils.text import indent, wrap_paragraphs File "/usr/lib/python3/dist-packages/IPython/utils/text.py", line 28, in <module> from IPython.external.path import path File "/usr/lib/python3/dist-packages/IPython/external/path/__init__.py", line 2, in <module> from path import * File "/home/jhammel/python/path.py", line 25 print root(path) ^
author Jeff Hammel <k0scist@gmail.com>
date Wed, 09 Jul 2014 16:26:49 -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)