view python/which.py @ 170:3e52d6bcac99

add the which thingy
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 26 Sep 2011 16:45:02 -0700
parents
children b91750a108b2
line wrap: on
line source

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 mozinfo.isWin:
            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)