Commit 0a6230de authored by Piotr Miedzik's avatar Piotr Miedzik Committed by Javier D. Garcia-Lasheras

which: use pure python code to find executable

parent a02f00dc
......@@ -65,11 +65,12 @@ class ToolMakefile(object):
"""Check if the binary is available in the O.S. environment"""
def _get_path(name):
"""Get the directory in which the tool binary is at Host"""
location = os.popen(
path_mod.which_cmd() + " %s" %
name).read().split('\n', 1)[0].strip()
logging.debug("location for %s: %s", name, location)
return os.path.dirname(location)
locations = path_mod.which(name)
if len(locations) == 0 :
return
logging.debug("location for %s: %s", name, locations[0])
return os.path.dirname(locations[0])
def _is_in_path(name, path=None):
"""Check if the directory is in the system path"""
......
......@@ -199,6 +199,16 @@ def mkdir_command():
return "mkdir -p"
def which(filename):
"""docstring for which"""
locations = os.environ.get("PATH").split(os.pathsep)
candidates = []
for location in locations:
candidate = os.path.join(location, filename)
if os.path.isfile(candidate):
candidates.append(candidate)
return candidates
def which_cmd():
"""Get a string with the O.S. specific which command"""
if check_windows():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment