diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-04-02 11:44:30 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-04-02 11:44:30 +0200 |
| commit | 41f39d2b69bb0747c1aed63c84d440b32b303d2c (patch) | |
| tree | 527d1e453f8ce2903f6fede8709c5760300cdf70 | |
| parent | 7f19d36ced806ffd138c4b48de6145068cc4f0b3 (diff) | |
| download | allocbench-41f39d2b69bb0747c1aed63c84d440b32b303d2c.tar.gz allocbench-41f39d2b69bb0747c1aed63c84d440b32b303d2c.zip | |
move find_cmd to src/util.py
| -rw-r--r-- | src/benchmark.py | 29 | ||||
| -rw-r--r-- | src/util.py | 21 |
2 files changed, 26 insertions, 24 deletions
diff --git a/src/benchmark.py b/src/benchmark.py index 2fea8df..23efb1e 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -132,33 +132,14 @@ class Benchmark (object): self.results[s][allocator] = d def prepare(self): - def is_exe(fpath): - return os.path.isfile(fpath) and os.access(fpath, os.X_OK) - - os.environ["PATH"] += ":" + os.path.join("build", "benchmarks", - self.name) + os.environ["PATH"] += os.pathsep + os.path.join("build", "benchmarks", self.name) for r in self.requirements: - fpath, fname = os.path.split(r) - - # Search for file - if fpath: - if not is_exe(r): - raise Exception("Requirement: {} not found".format(r)) - else: - self.results["facts"]["libcs"][exe_file] = src.facter.get_libc_version(bin=exe_file) - # Search in PATH + exe = find_cmd(r) + if exe is not None: + self.results["facts"]["libc"][r] = src.facter.get_libc_version(bin=exe) else: - found = False - for path in os.environ["PATH"].split(os.pathsep): - exe_file = os.path.join(path, r) - if is_exe(exe_file): - self.results["facts"]["libcs"][exe_file] = src.facter.get_libc_version(bin=exe_file) - found = True - break - - if not found: - raise Exception("Requirement: {} not found".format(r)) + raise Exception("Requirement: {} not found".format(r)) def iterate_args(self, args=None): """Return a dict for each possible combination of args""" diff --git a/src/util.py b/src/util.py index b7d4541..b9f3ce6 100644 --- a/src/util.py +++ b/src/util.py @@ -1,7 +1,28 @@ +import os import sys import src.globalvars + +def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + +def find_cmd(cmd): + fpath, fname = os.path.split(cmd) + + # Search for file + if fpath: + if is_exe(cmd): + return cmd + # Search in PATH + else: + for path in os.environ["PATH"].split(os.pathsep): + exe_file = os.path.join(path, cmd) + if is_exe(exe_file): + return exe_file + + return None + def allocbench_msg(color, *objects, sep=' ', end='\n', file=sys.stdout): if src.globalvars.verbosity < 0: return |
