summaryrefslogtreecommitdiff
path: root/xnt/tasks.py
diff options
context:
space:
mode:
Diffstat (limited to 'xnt/tasks.py')
-rw-r--r--xnt/tasks.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/xnt/tasks.py b/xnt/tasks.py
index ab93f97..c11a13b 100644
--- a/xnt/tasks.py
+++ b/xnt/tasks.py
@@ -162,3 +162,25 @@ def setup(commands, directory=""):
error_code = call(cmd)
os.chdir(cwd)
return error_code
+
+def which(program):
+ """Similar to Linux/Unix `which`: return (first) path of executable"""
+ def is_exe(fpath):
+ """Determine if argument exists and is executable"""
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath = os.path.split(program)
+ if fpath[0]:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ path = path.strip('"')
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+ return None
+
+def in_path(program):
+ """Return boolean result if program is in PATH environment variable"""
+ return which(program)