def _which(self, program):
"""Simple function to determine the path of an executable.
Borrowed from https://github.com/amoffat/sh/blob/master/sh.py#L300.
Thanks Andrew Moffat! sh is pretty awesome :^)
"""
def is_exe(fpath):
return (os.path.exists(fpath) and
os.access(fpath, os.X_OK) and
os.path.isfile(os.path.realpath(fpath)))
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
if "PATH" not in os.environ:
return None
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
评论列表
文章目录