util: add backport for shutil.which()

nistp521
Roman Zeyde 7 years ago
parent 4926d4f4d3
commit 9bbc66cc16
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

@ -4,7 +4,6 @@ import contextlib
import functools import functools
import io import io
import logging import logging
import shutil
import struct import struct
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -219,7 +218,13 @@ def memoize(func):
@memoize @memoize
def which(cmd): def which(cmd):
"""Return full path to specified command, or raise OSError if missing.""" """Return full path to specified command, or raise OSError if missing."""
full_path = shutil.which(cmd) try:
# For Python 3
from shutil import which as _which
except ImportError:
# For Python 2
from backports.shutil_which import which as _which # pylint: disable=relative-import
full_path = _which(cmd)
if full_path is None: if full_path is None:
raise OSError('Cannot find {!r} in $PATH'.format(cmd)) raise OSError('Cannot find {!r} in $PATH'.format(cmd))
log.debug('which %r => %r', cmd, full_path) log.debug('which %r => %r', cmd, full_path)

@ -15,6 +15,7 @@ setup(
'libagent.ssh' 'libagent.ssh'
], ],
install_requires=[ install_requires=[
'backports.shutil_which>=3.5.1',
'ecdsa>=0.13', 'ecdsa>=0.13',
'ed25519>=1.4', 'ed25519>=1.4',
'pymsgbox>=1.0.6', 'pymsgbox>=1.0.6',

Loading…
Cancel
Save