# HG changeset patch # User Jeff Hammel # Date 1487615247 28800 # Node ID bcd62e6d822c812c7aef7d0262dbcf4cfef02c4d initial commit diff -r 000000000000 -r bcd62e6d822c README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Mon Feb 20 10:27:27 2017 -0800 @@ -0,0 +1,11 @@ +whichpy +=========== + +python equivalent of which + +---- + +Jeff Hammel + +https://pypi.python.org/pypi/whichpy + diff -r 000000000000 -r bcd62e6d822c setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Mon Feb 20 10:27:27 2017 -0800 @@ -0,0 +1,35 @@ +import os +from setuptools import setup + +try: + here = os.path.dirname(os.path.abspath(__file__)) + description = open(os.path.join(here, 'README.txt')).read() +except IOError: + description = None + +version = '0.0' + +deps = [] + +setup(name='whichpy', + version=version, + description="python equivalent of which", + long_description=description, + classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers + keywords='', + author='Jeff Hammel', + author_email='k0scist@gmail.com', + url='https://pypi.python.org/pypi/whichpy', + license='', + py_modules=['which'], + packages=[], + include_package_data=True, + zip_safe=False, + install_requires=deps, + entry_points=""" + # -*- Entry points: -*- + [console_scripts] + which.py = which:main + """, + ) + diff -r 000000000000 -r bcd62e6d822c which.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/which.py Mon Feb 20 10:27:27 2017 -0800 @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import os +import sys + +def which(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") + +def main(args=sys.argv[1:]): + """CLI""" + for i in sys.argv[1:]: + print which(i) + +if __name__ == '__main__': + main()