Commit ce813aaf authored by Martín Ferrari's avatar Martín Ferrari

Make find_bin search in system PATH first. Export find_bin_*

parent 81747f7d
...@@ -6,32 +6,37 @@ __all__ = ["ip_path", "tc_path", "brctl_path", "sysctl_path", "hz"] ...@@ -6,32 +6,37 @@ __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):
search = []
if "PATH" in os.environ:
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)
for d in search:
try: try:
os.stat(pref + d + name) os.stat(d + name)
return pref + d + name return d + name
except OSError, e: except OSError, e:
if e.errno != os.errno.ENOENT: if e.errno != os.errno.ENOENT:
raise raise
return None return None
def _find_bin_or_die(name): def find_bin_or_die(name):
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 " +
"continue.") % name) "continue.") % name)
return r return r
ip_path = _find_bin_or_die("ip") ip_path = find_bin_or_die("ip")
tc_path = _find_bin_or_die("tc") tc_path = find_bin_or_die("tc")
brctl_path = _find_bin_or_die("brctl") brctl_path = find_bin_or_die("brctl")
sysctl_path = _find_bin_or_die("sysctl") sysctl_path = find_bin_or_die("sysctl")
# Optional tools # Optional tools
tcpdump_path = _find_bin("tcpdump") tcpdump_path = find_bin("tcpdump")
netperf_path = _find_bin("netperf") netperf_path = find_bin("netperf")
# Seems this is completely bogus. At least, we can assume that the internal HZ # Seems this is completely bogus. At least, we can assume that the internal HZ
# is bigger than this. # is bigger than this.
......
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