Commit 117f91fa authored by Martín Ferrari's avatar Martín Ferrari

Allow user-specified search paths in find_bin

parent ce813aaf
...@@ -6,13 +6,16 @@ __all__ = ["ip_path", "tc_path", "brctl_path", "sysctl_path", "hz"] ...@@ -6,13 +6,16 @@ __all__ = ["ip_path", "tc_path", "brctl_path", "sysctl_path", "hz"]
__all__ += ["tcpdump_path", "netperf_path"] __all__ += ["tcpdump_path", "netperf_path"]
__all__ += ["execute", "backticks"] __all__ += ["execute", "backticks"]
def find_bin(name): def find_bin(name, extra_path = None):
search = [] search = []
if "PATH" in os.environ: if "PATH" in os.environ:
search += os.environ["PATH"].split(":") search += os.environ["PATH"].split(":")
for pref in ("/", "/usr/", "/usr/local/"): for pref in ("/", "/usr/", "/usr/local/"):
for d in ("bin/", "sbin/"): for d in ("bin/", "sbin/"):
search.append(pref + d) search.append(pref + d)
if extra_path:
search += extra_path
for d in search: for d in search:
try: try:
os.stat(d + name) os.stat(d + name)
...@@ -22,7 +25,7 @@ def find_bin(name): ...@@ -22,7 +25,7 @@ def find_bin(name):
raise raise
return None return None
def find_bin_or_die(name): def find_bin_or_die(name, extra_path = None):
r = find_bin(name) r = find_bin(name)
if not r: if not r:
raise RuntimeError(("Cannot find `%s' command, impossible to " + raise RuntimeError(("Cannot find `%s' command, impossible to " +
......
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