#!/usr/bin/env python

__version__ = '0.4.0'


if __name__ == '__main__':
    import sys
    import re
    from importlib import import_module

    if len(sys.argv) == 1:
        sys.exit(1)

    failed = False

    for pkg in sys.argv[1:]:
        try:
            f = import_module(pkg).__file__
            f = re.sub(r'\.pyc$', '.py', f)  # .pyc to .py
            f = re.sub(r'__init__\.py$', '', f)  # Drop an __init__.py
            sys.stdout.write('{0}\n'.format(f))
        except ImportError:
            sys.stderr.write('{0} not found\n'.format(pkg))
            failed = True

    if failed:
        sys.exit(1)
    sys.exit(0)
