From 41f39d2b69bb0747c1aed63c84d440b32b303d2c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 2 Apr 2019 11:44:30 +0200 Subject: move find_cmd to src/util.py --- src/util.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/util.py') 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 -- cgit v1.2.3