VirtualBox

Ignore:
Timestamp:
Oct 15, 2020 10:50:24 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
140952
Message:

common/utils.py: Adding whichProgram. bugref:9841

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/utils.py

    r84568 r86588  
    832832
    833833
     834def whichProgram(sName, sPath = None):
     835    """
     836    Works similar to the 'which' utility on unix.
     837
     838    Returns path to the given program if found.
     839    Returns None if not found.
     840    """
     841    sHost = getHostOs();
     842    sSep  = ';' if sHost in [ 'win', 'os2' ] else ':';
     843
     844    if sPath is None:
     845        if sHost == 'win':
     846            sPath = os.environ.get('Path', None);
     847        else:
     848            sPath = os.environ.get('PATH', None);
     849        if sPath is None:
     850            return None;
     851
     852    for sDir in sPath.split(sSep):
     853        if sDir.strip() != '':
     854            sTest = os.path.abspath(os.path.join(sDir, sName));
     855        else:
     856            sTest = os.path.abspath(sName);
     857        if os.path.exists(sTest):
     858            return sTest;
     859
     860    return None;
     861
    834862#
    835863# Generic process stuff.
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette