def which(program, win_allow_cross_arch=True):
def is_exe(path):<EOL><INDENT>return os.path.isfile(path) and os.access(path, os.X_OK)<EOL><DEDENT>def _get_path_list():<EOL><INDENT>return os.environ['<STR_LIT>'].split(os.pathsep)<EOL><DEDENT>if os.name == '<STR_LIT>':<EOL><INDENT>def find_exe(program):<EOL><INDENT>root, ext = os.path.splitext(program)<EOL>if ext:<EOL><INDENT>if is_exe(program):<EOL><INDENT>return program<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for ext in os.environ['<STR_LIT>'].split(os.pathsep):<EOL><INDENT>program_path = root + ext.lower()<EOL>if is_exe(program_path):<EOL><INDENT>return program_path<EOL><DEDENT><DEDENT><DEDENT>return None<EOL><DEDENT>def get_path_list():<EOL><INDENT>paths = _get_path_list()<EOL>if win_allow_cross_arch:<EOL><INDENT>alt_sys_path = os.path.expandvars(r"<STR_LIT>")<EOL>if os.path.isdir(alt_sys_path):<EOL><INDENT>paths.insert(<NUM_LIT:0>, alt_sys_path)<EOL><DEDENT>else:<EOL><INDENT>alt_sys_path = os.path.expandvars(r"<STR_LIT>")<EOL>if os.path.isdir(alt_sys_path):<EOL><INDENT>paths.append(alt_sys_path)<EOL><DEDENT><DEDENT><DEDENT>return paths<EOL><DEDENT><DEDENT>else:<EOL><INDENT>def find_exe(program):<EOL><INDENT>return program if is_exe(program) else None<EOL><DEDENT>get_path_list = _get_path_list<EOL><DEDENT>if os.path.split(program)[<NUM_LIT:0>]:<EOL><INDENT>program_path = find_exe(program)<EOL>if program_path:<EOL><INDENT>return program_path<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for path in get_path_list():<EOL><INDENT>program_path = find_exe(os.path.join(path, program))<EOL>if program_path:<EOL><INDENT>return program_path<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>
Identify the location of an executable file.