view python/which.py @ 216:07d8aa100fc2

enable hg share extension http://mercurial.selenic.com/wiki/ShareExtension
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 05 Apr 2012 10:55:49 -0700
parents b91750a108b2
children e4221e45d6c1
line wrap: on
line source

#!/usr/bin/env python

import os
import sys

def findInPath(fileName, path=os.environ['PATH']):
    """python equivalent of which; should really be in the stdlib"""
    dirs = path.split(os.pathsep)
    for dir in dirs:
        if os.path.isfile(os.path.join(dir, fileName)):
            return os.path.join(dir, fileName)
        if os.path.isfile(os.path.join(dir, fileName + ".exe")):
            return os.path.join(dir, fileName + ".exe")

if __name__ == '__main__':
    for i in sys.argv[1:]:
        print findInPath(i)