def find_executable(name, names=None, required=True):
    """Utility function to find an executable in PATH
    name: program to find. Use given value if absolute path

    names: list of additional names. For instance

       >>> find_executable('sed', names=['gsed'])

    required: If True, then the function raises an Exception
    if the program is not found else the function returns name if
    the program is not found.
    """
    path_from_env = os.environ.get(name.upper())
    if path_from_env is not None:
        return path_from_env
    names = [name] + (names or [])
    for _name in names:
        if osp.isabs(_name):
            return _name
        paths = os.environ.get('PATH', '').split(os.pathsep)
        eax = find_in_paths(_name, paths)
        if eax:
            return eax
    if required:
        raise NameError('Could not find %s executable' % name)
    else:
        return name
Utility function to find an executable in PATH
    name: program to find. Use given value if absolute path

    names: list of additional names. For instance

       >>> find_executable('sed', names=['gsed'])

    required: If True, then the function raises an Exception
    if the program is not found else the function returns name if
    the program is not found.