summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-11-01 00:19:44 +0000
committerRadostin Stoyanov <rstoyanov1@gmail.com>2017-11-21 11:32:21 +0000
commit4f0ea4dc53ce9097b673ef8541e9affd7fed4680 (patch)
treee779de0b6ecb9701cdf266145222736075700e82 /src
parent8549eee0a949fb809d496158ae44b985912dea6e (diff)
downloadvirt-bootstrap.git-4f0ea4dc53ce9097b673ef8541e9affd7fed4680.tar.gz
virt-bootstrap.git-4f0ea4dc53ce9097b673ef8541e9affd7fed4680.tar.xz
virt-bootstrap.git-4f0ea4dc53ce9097b673ef8541e9affd7fed4680.zip
utils: Add is_installed function
Add utility function to check whether an executable is available in the PATH env variable.
Diffstat (limited to 'src')
-rw-r--r--src/virtBootstrap/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
index 84d1629..ea84ed3 100644
--- a/src/virtBootstrap/utils.py
+++ b/src/virtBootstrap/utils.py
@@ -646,3 +646,16 @@ def mapping_uid_gid(dest, uid_map, gid_map):
balance_uid_gid_maps(uid_map, gid_map)
for uid, gid in zip(uid_map, gid_map):
map_id(dest, uid, gid)
+
+
+def is_installed(program):
+ """
+ Try to find executable listed in the PATH env variable.
+
+ Returns the complete filename or None if not found.
+ """
+ for path in os.environ["PATH"].split(os.pathsep):
+ exec_file = os.path.join(path, program)
+ if os.path.isfile(exec_file) and os.access(exec_file, os.X_OK):
+ return exec_file
+ return None