Mon, 01 Apr 2013 17:56:48 +0200
Added a function to Utilities to determine all possible full executable paths using the PATH environment variable.
--- a/APIs/Python3/eric5.api Mon Mar 25 10:29:59 2013 +0100 +++ b/APIs/Python3/eric5.api Mon Apr 01 17:56:48 2013 +0200 @@ -7940,6 +7940,7 @@ eric5.Utilities.getDirs?4(path, excludeDirs) eric5.Utilities.getEnvironmentEntry?4(key, default=None) eric5.Utilities.getExecutablePath?4(file) +eric5.Utilities.getExecutablePaths?4(file) eric5.Utilities.getHomeDir?4() eric5.Utilities.getPercentReplacement?4(code) eric5.Utilities.getPercentReplacementHelp?4()
--- a/Documentation/Help/source.qhp Mon Mar 25 10:29:59 2013 +0100 +++ b/Documentation/Help/source.qhp Mon Apr 01 17:56:48 2013 +0200 @@ -12364,6 +12364,7 @@ <keyword name="getEditorTyping" id="getEditorTyping" ref="eric5.Preferences.__init__.html#getEditorTyping" /> <keyword name="getEnvironmentEntry" id="getEnvironmentEntry" ref="eric5.Utilities.__init__.html#getEnvironmentEntry" /> <keyword name="getExecutablePath" id="getExecutablePath" ref="eric5.Utilities.__init__.html#getExecutablePath" /> + <keyword name="getExecutablePaths" id="getExecutablePaths" ref="eric5.Utilities.__init__.html#getExecutablePaths" /> <keyword name="getExistingDirectory" id="getExistingDirectory" ref="eric5.E5Gui.E5FileDialog.html#getExistingDirectory" /> <keyword name="getExporter" id="getExporter" ref="eric5.QScintilla.Exporters.__init__.html#getExporter" /> <keyword name="getFileNameFromUrl" id="getFileNameFromUrl" ref="eric5.Helpviewer.HelpUtilities.html#getFileNameFromUrl" />
--- a/Documentation/Source/eric5.Utilities.__init__.html Mon Mar 25 10:29:59 2013 +0100 +++ b/Documentation/Source/eric5.Utilities.__init__.html Mon Apr 01 17:56:48 2013 +0200 @@ -112,6 +112,9 @@ <td><a href="#getExecutablePath">getExecutablePath</a></td> <td>Function to build the full path of an executable file from the environment.</td> </tr><tr> +<td><a href="#getExecutablePaths">getExecutablePaths</a></td> +<td>Function to build all full path of an executable file from the environment.</td> +</tr><tr> <td><a href="#getHomeDir">getHomeDir</a></td> <td>Function to get a users home directory</td> </tr><tr> @@ -822,6 +825,26 @@ </dl> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> +<a NAME="getExecutablePaths" ID="getExecutablePaths"></a> +<h2>getExecutablePaths</h2> +<b>getExecutablePaths</b>(<i>file</i>) +<p> + Function to build all full path of an executable file from the environment. +</p><dl> +<dt><i>file</i></dt> +<dd> +filename of the executable (string) +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +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. +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> <a NAME="getHomeDir" ID="getHomeDir"></a> <h2>getHomeDir</h2> <b>getHomeDir</b>(<i></i>)
--- 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.