Utilities/__init__.py

branch
5_3_x
changeset 2557
bf643d8b37fc
parent 2302
f29e9405c851
child 2611
dd77cc80e343
--- a/Utilities/__init__.py	Mon Mar 25 10:29:59 2013 +0100
+++ b/Utilities/__init__.py	Mon Apr 01 17:56:48 2013 +0200
@@ -769,6 +769,41 @@
     return ""
     
 
+def getExecutablePaths(file):
+    """
+    Function to build all full path of an executable file from the environment.
+    
+    @param file filename of the executable (string)
+    @return list of full executable names (list of strings), if the executable file
+        is accessible via the searchpath defined by the PATH environment variable,
+        or an empty list otherwise.
+    """
+    paths = []
+    
+    if os.path.isabs(file):
+        if os.access(file, os.X_OK):
+            return [file]
+        else:
+            return []
+        
+    cur_path = os.path.join(os.curdir, file)
+    if os.path.exists(cur_path):
+        if os.access(cur_path, os.X_OK):
+            paths.append(cur_path)
+
+    path = os.getenv('PATH')
+    
+    # environment variable not defined
+    if path is not None:
+        dirs = path.split(os.pathsep)
+        for dir in dirs:
+            exe = os.path.join(dir, file)
+            if os.access(exe, os.X_OK) and exe not in paths:
+                paths.append(exe)
+    
+    return paths
+    
+
 def isExecutable(exe):
     """
     Function to check, if a file is executable.

eric ide

mercurial