1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-28 15:58:40 +00:00

#N/A: Use shutil.which when possible

This commit is contained in:
nvbn 2016-02-06 16:42:42 +03:00
parent 28d078708b
commit bbfd53d718

View File

@ -46,22 +46,26 @@ memoize.disabled = False
@memoize @memoize
def which(program): def which(program):
"""Returns `program` path or `None`.""" """Returns `program` path or `None`."""
try:
from shutil import which
def is_exe(fpath): return which(program)
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) except ImportError:
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program) fpath, fname = os.path.split(program)
if fpath: if fpath:
if is_exe(program): if is_exe(program):
return program return program
else: else:
for path in os.environ["PATH"].split(os.pathsep): for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"') path = path.strip('"')
exe_file = os.path.join(path, program) exe_file = os.path.join(path, program)
if is_exe(exe_file): if is_exe(exe_file):
return exe_file return exe_file
return None return None
def default_settings(params): def default_settings(params):