mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
utils/ssh: Remove _check_env()
Replace _check_env() by lazily initialized global var.
This commit is contained in:
parent
926aee1833
commit
c39d40c6f8
@ -67,9 +67,17 @@ from devlib.connection import (ConnectionBase, ParamikoBackgroundCommand, PopenB
|
|||||||
DEFAULT_SSH_SUDO_COMMAND = "sudo -k -p ' ' -S -- sh -c {}"
|
DEFAULT_SSH_SUDO_COMMAND = "sudo -k -p ' ' -S -- sh -c {}"
|
||||||
|
|
||||||
|
|
||||||
ssh = None
|
# Lazy init of some globals
|
||||||
scp = None
|
def __getattr__(attr):
|
||||||
sshpass = None
|
if attr in {'ssh', 'scp', 'sshpass'}:
|
||||||
|
path = which(attr)
|
||||||
|
if path:
|
||||||
|
globals()[attr] = path
|
||||||
|
return path
|
||||||
|
else:
|
||||||
|
raise HostError(f'OpenSSH must be installed on the host: could not find {attr} command')
|
||||||
|
else:
|
||||||
|
raise AttributeError(f"Module '{__name__}' has no attribute '{attr}'")
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('ssh')
|
logger = logging.getLogger('ssh')
|
||||||
@ -176,7 +184,6 @@ def telnet_get_shell(host,
|
|||||||
port=None,
|
port=None,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
original_prompt=None):
|
original_prompt=None):
|
||||||
_check_env()
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
while True:
|
while True:
|
||||||
conn = TelnetPxssh(original_prompt=original_prompt)
|
conn = TelnetPxssh(original_prompt=original_prompt)
|
||||||
@ -792,7 +799,6 @@ class TelnetConnection(SshConnectionBase):
|
|||||||
strict_host_check=strict_host_check,
|
strict_host_check=strict_host_check,
|
||||||
)
|
)
|
||||||
|
|
||||||
_check_env()
|
|
||||||
self.options = self._get_default_options()
|
self.options = self._get_default_options()
|
||||||
|
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
@ -1607,16 +1613,6 @@ def _give_password(password, command):
|
|||||||
return (pass_string + command, redacted_string + command)
|
return (pass_string + command, redacted_string + command)
|
||||||
|
|
||||||
|
|
||||||
def _check_env():
|
|
||||||
global ssh, scp, sshpass # pylint: disable=global-statement
|
|
||||||
if not ssh:
|
|
||||||
ssh = which('ssh')
|
|
||||||
scp = which('scp')
|
|
||||||
sshpass = which('sshpass')
|
|
||||||
if not (ssh and scp):
|
|
||||||
raise HostError('OpenSSH must be installed on the host.')
|
|
||||||
|
|
||||||
|
|
||||||
def process_backspaces(text):
|
def process_backspaces(text):
|
||||||
chars = []
|
chars = []
|
||||||
for c in text:
|
for c in text:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user