Add function which implements the bash 'which' feature.
* Add function _which(), which is shamelessly stolen from Twisted's twisted.python.procutils module.feature/documentation-builds-dirhtml
parent
7eff7b4a03
commit
8133abd851
38
gnupg.py
38
gnupg.py
|
@ -858,6 +858,44 @@ def _sanitise(*args, **kwargs):
|
|||
|
||||
return sanitised
|
||||
|
||||
def _which(executable, flags=os.X_OK):
|
||||
"""Shamelessly pilfered from Twisted's :mod:`twisted.python.proutils`.
|
||||
|
||||
Search PATH for executable files with the given name.
|
||||
|
||||
On newer versions of MS-Windows, the PATHEXT environment variable will be
|
||||
set to the list of file extensions for files considered executable. This
|
||||
will normally include things like ".EXE". This fuction will also find files
|
||||
with the given name ending with any of these extensions.
|
||||
|
||||
On MS-Windows the only flag that has any meaning is os.F_OK. Any other
|
||||
flags will be ignored.
|
||||
|
||||
@type name: C{str}
|
||||
@param name: The name for which to search.
|
||||
|
||||
@type flags: C{int}
|
||||
@param flags: Arguments to L{os.access}.
|
||||
|
||||
@rtype: C{list}
|
||||
@param: A list of the full paths to files found, in the order in which
|
||||
they were found.
|
||||
"""
|
||||
result = []
|
||||
exts = filter(None, os.environ.get('PATHEXT', '').split(os.pathsep))
|
||||
path = os.environ.get('PATH', None)
|
||||
if path is None:
|
||||
return []
|
||||
for p in os.environ.get('PATH', '').split(os.pathsep):
|
||||
p = os.path.join(p, name)
|
||||
if os.access(p, flags):
|
||||
result.append(p)
|
||||
for e in exts:
|
||||
pext = p + e
|
||||
if os.access(pext, flags):
|
||||
result.append(pext)
|
||||
return result
|
||||
|
||||
class GPG(object):
|
||||
"""Encapsulate access to the gpg executable"""
|
||||
decode_errors = 'strict'
|
||||
|
|
Loading…
Reference in New Issue