~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/python/procutils.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
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