|
Revision 22742, 1.3 kB
(checked in by radix, 1 year ago)
|
Merge api-stability-removal-2847
Remove all "API Stability" markers, as they were causing more grief than good,
and we have a universally strict compatibility policy, so they have long
been irrelevent.
Author: radix
Reviewer: therve
Fixes #2847
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
""" |
|---|
| 5 |
Utilities for dealing with processes. |
|---|
| 6 |
""" |
|---|
| 7 |
|
|---|
| 8 |
import os |
|---|
| 9 |
|
|---|
| 10 |
def which(name, flags=os.X_OK): |
|---|
| 11 |
"""Search PATH for executable files with the given name. |
|---|
| 12 |
|
|---|
| 13 |
On newer versions of MS-Windows, the PATHEXT environment variable will be |
|---|
| 14 |
set to the list of file extensions for files considered executable. This |
|---|
| 15 |
will normally include things like ".EXE". This fuction will also find files |
|---|
| 16 |
with the given name ending with any of these extensions. |
|---|
| 17 |
|
|---|
| 18 |
On MS-Windows the only flag that has any meaning is os.F_OK. Any other |
|---|
| 19 |
flags will be ignored. |
|---|
| 20 |
|
|---|
| 21 |
@type name: C{str} |
|---|
| 22 |
@param name: The name for which to search. |
|---|
| 23 |
|
|---|
| 24 |
@type flags: C{int} |
|---|
| 25 |
@param flags: Arguments to L{os.access}. |
|---|
| 26 |
|
|---|
| 27 |
@rtype: C{list} |
|---|
| 28 |
@param: A list of the full paths to files found, in the |
|---|
| 29 |
order in which they were found. |
|---|
| 30 |
""" |
|---|
| 31 |
result = [] |
|---|
| 32 |
exts = filter(None, os.environ.get('PATHEXT', '').split(os.pathsep)) |
|---|
| 33 |
path = os.environ.get('PATH', None) |
|---|
| 34 |
if path is None: |
|---|
| 35 |
return [] |
|---|
| 36 |
for p in os.environ.get('PATH', '').split(os.pathsep): |
|---|
| 37 |
p = os.path.join(p, name) |
|---|
| 38 |
if os.access(p, flags): |
|---|
| 39 |
result.append(p) |
|---|
| 40 |
for e in exts: |
|---|
| 41 |
pext = p + e |
|---|
| 42 |
if os.access(pext, flags): |
|---|
| 43 |
result.append(pext) |
|---|
| 44 |
return result |
|---|
| 45 |
|
|---|