diff options
author | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2020-10-15 10:50:24 +0000 |
---|---|---|
committer | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2020-10-15 10:50:24 +0000 |
commit | 3d273fd779dc87998f01b5eab7c8bf067ac2b398 (patch) | |
tree | 356887adee1110f562cacfa70caf871d558a20f4 /src/VBox/ValidationKit/common | |
parent | 553d12b7f87ad9bc9fa559cd7e60175e349f6320 (diff) | |
download | VirtualBox-svn-3d273fd779dc87998f01b5eab7c8bf067ac2b398.tar.gz |
common/utils.py: Adding whichProgram. bugref:9841
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@86588 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/ValidationKit/common')
-rw-r--r-- | src/VBox/ValidationKit/common/utils.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/VBox/ValidationKit/common/utils.py b/src/VBox/ValidationKit/common/utils.py index 5ff39919aea..c8aba11897e 100644 --- a/src/VBox/ValidationKit/common/utils.py +++ b/src/VBox/ValidationKit/common/utils.py @@ -831,6 +831,34 @@ def sudoProcessPopen(*aPositionalArgs, **dKeywordArgs): return processPopenSafe(*aPositionalArgs, **dKeywordArgs); +def whichProgram(sName, sPath = None): + """ + Works similar to the 'which' utility on unix. + + Returns path to the given program if found. + Returns None if not found. + """ + sHost = getHostOs(); + sSep = ';' if sHost in [ 'win', 'os2' ] else ':'; + + if sPath is None: + if sHost == 'win': + sPath = os.environ.get('Path', None); + else: + sPath = os.environ.get('PATH', None); + if sPath is None: + return None; + + for sDir in sPath.split(sSep): + if sDir.strip() != '': + sTest = os.path.abspath(os.path.join(sDir, sName)); + else: + sTest = os.path.abspath(sName); + if os.path.exists(sTest): + return sTest; + + return None; + # # Generic process stuff. # |